4

Tried to copy the file HU98373+TRRepr#o4_201702061135_34 from local system to remote destination using curl FTP.

In remote system it has created file with HU98373+TRRepr but not HU98373+TRRepr#o4_201702061135_34. I don't know why it is not considering '#' character

Please check the below code.

remoteFileUrl = ftp://IPADRESS/HOME/HU98373+TRRepr#o4_201702061135_34.tmp/C20170206.1135-20170206.1140

curl_easy_setopt(m_CurlSessionHandle, CURLOPT_URL, remoteFileUrl);
                        curl_easy_setopt(m_CurlSessionHandle, CURLOPT_UPLOAD, ON);

                        // Set the input local file handle
                        curl_easy_setopt(m_CurlSessionHandle, CURLOPT_READDATA, localFileHandle);

                        // Set on/off all wanted options
                        // Enable ftp data connection
                        curl_easy_setopt(m_CurlSessionHandle, CURLOPT_NOBODY, OFF);

                        // Create missing directory into FTP path
                        curl_easy_setopt(m_CurlSessionHandle, CURLOPT_FTP_CREATE_MISSING_DIRS , ON) ;

                        // Set the progress function, in oder to check the stop transfer request
                        curl_easy_setopt(m_CurlSessionHandle, CURLOPT_NOPROGRESS, OFF);
                        curl_easy_setopt(m_CurlSessionHandle, CURLOPT_PROGRESSFUNCTION, progressCb);
                        curl_easy_setopt(m_CurlSessionHandle, CURLOPT_PROGRESSDATA, this);

                        CURLcode curlOperationResult = curl_easy_perform(m_CurlSessionHandle);

Can any one help me on this

rohit
  • 65
  • 10

1 Answers1

0

A URL is composed by the following parts:

 scheme:[//[user:password@]host[:port]][/]path[?query][#fragment]

The characeter # indicates the URL fragment. You must URL encode the # character so that it is not interpreted as a fragment separator.

Once encoded, the server will parse the URL as expected and the correct file name will be generated.

The following question displayes how to do this in C++:

Encode/Decode URLs in C++

Community
  • 1
  • 1
  • remote file url:.....encoded url:... got errorcode: 6, Couldn't resolve host name...could you please tell me how to proceed – rohit Feb 08 '17 at 13:51
  • after encoding the url above libcurl call failed with errorcode : 6 Couldn't resolve host name – rohit Feb 08 '17 at 14:05
  • i encoded # to %23 and i didn't touch the remaining string, during upload of file [post], got error 18, Transferred a partial file, server did not report OK, got 426 – rohit Feb 08 '17 at 14:50
  • using curl 7.37.0 – rohit Feb 08 '17 at 14:59
  • Thanks Vinicius, There was a problem with FTP server, after replacing FTP server it worked. Thank you for answering – rohit Feb 10 '17 at 06:36
  • Sorry, I just saw your comments. Nice, congratulations! – Vinícius Gobbo A. de Oliveira Feb 10 '17 at 12:08
  • There is still some problem with FTP server...It was able to create a new directory copied the contents to the directory. During rename of the directory some thing happened, after that whenever i tried to look for any existing directory it will return success even though that directory is not present in the remote sysytem – rohit Feb 13 '17 at 08:45
  • 02-10-2017 11:15:16 IP 141.137.47.34 FTP ftpuser01 is changing dir to / (D:\Program Files (x86)\freeFTPd\ftproot\ftpuser01\) 02-10-2017 11:15:17 IP 141.137.47.34 FTP ftpuser01 is making directory /ABCD (D:\Program Files (x86)\freeFTPd\ftproot\ftpuser01\ABCD) 02-10-2017 11:15:17 IP 141.137.47.34 FTP ftpuser01 is changing dir to /ABCD (D:\Program Files (x86)\freeFTPd\ftproot\ftpuser01\ABCD\) – rohit Feb 13 '17 at 08:53
  • 02-10-2017 11:15:19 IP 141.137.47.34 FTP ftpuser01 is uploading /ABCD/HU98373+trrEPR#O4_201702081950_27.tmp/status201702081950 (D:\Program Files (x86)\freeFTPd\ftproot\ftpuser01\ABCD\HU98373+trrEPR#O4_201702081950_27.tmp\status201702081950) 02-10-2017 11:15:20 IP 141.137.47.34 FTP ftpuser01 transfer complete – rohit Feb 13 '17 at 08:54
  • 02-10-2017 11:15:20 IP 141.137.47.34 FTP ftpuser01 is renaming /ABCD/HU98373+trrEPR#O4_201702081950_27.tmp/ (D:\Program Files (x86)\freeFTPd\ftproot\ftpuser01\ABCD\HU98373+trrE) 02-10-2017 11:15:20 IP 141.137.47.34 FTP ftpuser01 disconnected 02-10-2017 11:15:21 IP 141.137.47.34 FTP connection attempt – rohit Feb 13 '17 at 08:54
  • 02-10-2017 11:15:21 IP 141.137.47.34 FTP ftpuser01 is changing dir to / (D:\Program Files (x86)\freeFTPd\ftproot\ftpuser01\) 02-10-2017 11:15:22 IP 141.137.47.34 FTP ftpuser01 is changing dir to /ABCD (D:\Program Files (x86)\freeFTPd\ftproot\ftpuser01\ABCD\) 02-10-2017 11:15:22 IP 141.137.47.34 FTP ftpuser01 is listing /ABCD (D:\Program Files (x86)\freeFTPd\ftproot\ftpuser01\ABCD\HU98373+trrEPR) 02-10-2017 11:15:22 IP 141.137.47.34 FTP ftpuser01 is changing dir to / (D:\Program Files (x86)\freeFTPd\ftproot\ftpuser01\) – rohit Feb 13 '17 at 08:55
  • 02-10-2017 11:15:23 IP 141.137.47.34 FTP ftpuser01 is listing /ABCD (D:\Program Files (x86)\freeFTPd\ftproot\ftpuser01\ABCD\HU98373+trrEPR) 02-10-2017 11:15:24 IP 141.137.47.34 FTP ftpuser01 is changing dir to / (D:\Program Files (x86)\freeFTPd\ftproot\ftpuser01\) 02-10-2017 11:15:24 IP 141.137.47.34 FTP ftpuser01 is changing dir to / (D:\Program Files (x86)\freeFTPd\ftproot\ftpuser01\) – rohit Feb 13 '17 at 08:55
  • The next folder I was trying to check in remote folder is HU98373+trrEPR#O4_201702081950_28...which is not there in remote system but still my libcurl call returns 0. Could you please help me out here, as i was stuck i don't know how to proceed – rohit Feb 13 '17 at 08:57
  • This looks like an issue with the chosen FTP server. I have no knowledge about the freeFTPd server. If they have a dedicated community, it might be better to post there and describe every step in detail. Sorry, I only know the protocol, this looks like implementation specific. – Vinícius Gobbo A. de Oliveira Feb 13 '17 at 14:59
  • Thanks Vinicius, File Transferred worked after changing the FTP server – rohit Feb 20 '17 at 08:06