cURL / Mailing Lists / curl-library / Single Mail

curl-library

Remote file information using sftp

From: Mele Giovanni <giovanni.mele_at_nagra.com>
Date: Tue, 4 Jan 2011 21:22:46 +0100

Hello,

I'm trying to get a remote file information, mainly size and
modification date) using the curl library. All is working fine when
connection on a normal ftp server, but as soon as I try to use an sftp
server, I get no information about the remote file. I'm using libcurl
7.21.3 compiled to enable sftp.

Here is what I do to get the remote file info:

                curl_easy_reset(_guts->_curl);

                curl_easy_setopt(_guts->_curl, CURLOPT_URL, (const
char*) (xURL + _guts->_machine
                                + xfolder));

                // Define our callback to get called when there's data
to be written
                curl_easy_setopt(_guts->_curl, CURLOPT_WRITEFUNCTION,
SEP::FTPCallback::FWrite);
                curl_easy_setopt(_guts->_curl, CURLOPT_WRITEDATA,
&myCallback);

                // Define username and password
                curl_easy_setopt(_guts->_curl, CURLOPT_USERPWD, (const
char*) (_guts->_username
                                + SEP::FTPUtilsGuts::_DOUBLE_DOT +
_guts->_password));

                // Switch on full protocol/debug output
                curl_easy_setopt(_guts->_curl, CURLOPT_VERBOSE, 1L);

                // set options for retrieving size and date
                curl_easy_setopt(_guts->_curl, CURLOPT_NOPROGRESS, 1);
                curl_easy_setopt(_guts->_curl, CURLOPT_NOBODY, 1);
                curl_easy_setopt(_guts->_curl, CURLOPT_HEADER, 1);
                curl_easy_setopt(_guts->_curl, CURLOPT_FILETIME, 1);

                CURLcode res = curl_easy_perform(_guts->_curl);

                if (res != 0) {
                        SEP::CString output = curl_easy_strerror(res);
                        SEP::CString xMsg("Failed to retrieve file info
for file ");
                        xMsg<<xURL<<_guts->_machine<<xfolder<<". Reason
is :"<<output;
                        throw FTPConnectionException(xMsg,
(SEP::Integer32) res, __FILE__, __LINE__);
                } else {
                        double xFileSize;
                        res = curl_easy_getinfo(_guts->_curl,
CURLINFO_CONTENT_LENGTH_DOWNLOAD, &xFileSize);
                        fileInfo._size = (SEP::Integer64)xFileSize;
                        if (res != 0)
                                throw FTPConnectionException("Unable to
retrieve file size", (SEP::Integer32) res, __FILE__, __LINE__);
                        long xFileTime;
                        res = curl_easy_getinfo(_guts->_curl,
CURLINFO_FILETIME , &xFileTime);
                        if (res != 0)
                                throw FTPConnectionException("Unable to
retrieve file mod date", (SEP::Integer32) res, __FILE__, __LINE__);
                        SEP::Date xDate((SEP::Integer64)xFileTime);
                        fileInfo._modDate = xDate;
                        cout<<"File "<<xURL<<_guts->_machine<<xfolder<<"
size = "<<fileInfo._size<<endl;
                        cout<<"File "<<xURL<<_guts->_machine<<xfolder<<"
mod date = "<<fileInfo._modDate.asString()<<endl;
                }

Is the problem caused by my sftp deamon or by my code?

Thx for the help

Giovanni

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2011-01-04