Commit a6cd27a6 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

add curl ftp test

parent 6bf33100
...@@ -784,6 +784,8 @@ int main(int argc, char *argv[]) ...@@ -784,6 +784,8 @@ int main(int argc, char *argv[])
fprintf(jobfilep, "#! /bin/bash\n"); fprintf(jobfilep, "#! /bin/bash\n");
fprintf(jobfilep, "uname -s\n"); fprintf(jobfilep, "uname -s\n");
fprintf(jobfilep, "pwd\n");
fprintf(jobfilep, "cd tmp\n");
fprintf(jobfilep, "setenv LD_LIBRARY_PATH /opt/gridware/sge/lib/lx24-x86:$LD_LIBRARY_PATH\n"); fprintf(jobfilep, "setenv LD_LIBRARY_PATH /opt/gridware/sge/lib/lx24-x86:$LD_LIBRARY_PATH\n");
fprintf(jobfilep, "%s\n", commandline); fprintf(jobfilep, "%s\n", commandline);
......
...@@ -58,6 +58,8 @@ extern int cdoTimer; ...@@ -58,6 +58,8 @@ extern int cdoTimer;
extern int cdoVerbose; extern int cdoVerbose;
extern int cdoDebug; extern int cdoDebug;
extern int cdoExpMode;
void cdiError(int cdiErrno, const char *fmt, ...); void cdiError(int cdiErrno, const char *fmt, ...);
void cdoAbort(const char *fmt, ...); void cdoAbort(const char *fmt, ...);
void cdoWarning(const char *fmt, ...); void cdoWarning(const char *fmt, ...);
......
...@@ -225,3 +225,86 @@ void job_submit(const char *expname, const char *jobfilename, const char *jobnam ...@@ -225,3 +225,86 @@ void job_submit(const char *expname, const char *jobfilename, const char *jobnam
#endif #endif
} }
#if defined (HAVE_LIBCURL)
# include <curl/curl.h>
# include <curl/types.h>
# include <curl/easy.h>
#endif
struct FtpFile {
char *filename;
FILE *stream;
};
int my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream)
{
struct FtpFile *out=(struct FtpFile *)stream;
if(out && !out->stream) {
out->stream=fopen(out->filename, "wb");
if(!out->stream)
return -1;
}
return fwrite(buffer, size, nmemb, out->stream);
}
int ftpput()
{
#if defined (HAVE_LIBCURL)
CURL *curl;
CURLcode res;
struct FtpFile ftpfile={
"b_eff.c", /* name to store the file as if succesful */
NULL
};
curl_global_init(CURL_GLOBAL_DEFAULT);
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_NETRC, CURL_NETRC_REQUIRED);
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
curl_easy_setopt(curl, CURLOPT_FTP_SSL, CURLFTPSSL_CONTROL);
curl_easy_setopt(curl, CURLOPT_FTPSSLAUTH, CURLFTPAUTH_TLS);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
curl_easy_setopt(curl, CURLOPT_SSLKEYPASSWD, "");
curl_easy_setopt(curl, CURLOPT_URL,
"ftp://qftps.zmaw.de/small/m214/m214089/benchmark/b_eff.c");
/* define callback */
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_fwrite);
/* set a pointer to struct to pass to the callback */
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &ftpfile);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
if(CURLE_OK != res) {
fprintf(stderr, "curl told us %d\n", res);
}
}
if(ftpfile.stream)
fclose(ftpfile.stream);
curl_global_cleanup();
#else
fprintf(stderr, "CURL library not available!\n");
#endif
return 0;
}
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
struct _PSTREAM { struct _PSTREAM {
int self; int self;
int mode;
int fileID; int fileID;
int vlistID; int vlistID;
int tsID; int tsID;
......
...@@ -517,6 +517,7 @@ int pstreamOpenRead(const char *argument) ...@@ -517,6 +517,7 @@ int pstreamOpenRead(const char *argument)
*/ */
cdoInqHistory(fileID); cdoInqHistory(fileID);
pstreamptr->mode = 'r';
pstreamptr->name = filename; pstreamptr->name = filename;
pstreamptr->fileID = fileID; pstreamptr->fileID = fileID;
} }
...@@ -586,6 +587,8 @@ int pstreamOpenWrite(const char *argument, int filetype) ...@@ -586,6 +587,8 @@ int pstreamOpenWrite(const char *argument, int filetype)
streamDefInstID(fileID, cdoDefaultInstID); streamDefInstID(fileID, cdoDefaultInstID);
*/ */
strcpy(filename, argument); strcpy(filename, argument);
pstreamptr->mode = 'w';
pstreamptr->name = filename; pstreamptr->name = filename;
pstreamptr->fileID = fileID; pstreamptr->fileID = fileID;
} }
...@@ -712,6 +715,16 @@ void pstreamClose(int pstreamID) ...@@ -712,6 +715,16 @@ void pstreamClose(int pstreamID)
streamClose(pstreamptr->fileID); streamClose(pstreamptr->fileID);
if ( cdoExpMode == CDO_EXP_REMOTE )
{
if ( pstreamptr->mode == 'w' )
{
fprintf(stderr, "start data transfer of %s\n", pstreamptr->name);
fprintf(stderr, "finish data transfer of %s\n", pstreamptr->name);
fprintf(stderr, "remove remote file %s\n", pstreamptr->name);
}
}
pstream_delete_entry(pstreamptr); pstream_delete_entry(pstreamptr);
} }
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment