From: | Marty Cantwell |
To: | Rob Spencer |
I'm assuming that all transfers completed correctly before your client moved their FTP server into the DMZ.
Could you try tacking on a zero byte file (or perhaps just a random dummy file) as the last file sent and see if the currently failing file writes successfully and the dummy then fails?
Marty
Hi Rick,
Our client has recently changed the network location of their servers to within their major firewall. We’re having some problems getting our FTP transfers to work.
I’ve modified the code to enable Passive FTP by setting the lPassiveFTP attribute on the FTP object. I’ve modified one of our applications to run an FTP upload with much more logging enabled. I’ve attached a few examples below to show the sort of things that I’ve thought of and tried.
Our application generates the output files that are to be transferred, so we’ve been able to transfer them to the remote FTP servers directly from the machine where we run our application using an ftp:// URL in Windows Explorer. It doesn’t work using the FTP client from the command line, which doesn’t support Passive mode. We’re running on Windows Server 2003 R2 SP1 (as a virtual machine) which has a direct outgoing FTP firewall rule, so no proxy server is required. Internet Explorer is configured to make only direct connections (and the proxy server would require a username/password). What all that waffle boils down to is that the FTP transfers do work, just not using our utility.
Latest build, run on-site:
<samp>
FTP via West Wind Web Connection 5.51
Connecting to janus.cnetdata.com as C04156
FTP Passive mode is On
Proxy Server is disabled
Connection Type : Direct
Connection Timeout : 25
Current folder : /
Changing current folder to Upload\
FTP Remote Folder change : Successful
Current folder : /Upload
Binary transfer is On
Failed to transfer D:\MFC04156.766 to Upload\, Error Code : 12002
FTP Message : The operation timed out
</samp>
This version of the application connects to the remote FTP server, checks a few of the setup properties, attempts to reset the lPassiveFTP property, set the remote directory and then uses FTPSendFileEx() to put the file on the remote server. Below I’ve also included a log file showing a successful transfer (on our test server) and the basic code (although you’ll just have to guess about some of the extra function calls). We’ve tried turning Passive mode off and it didn’t improve matters (I just wanted to make sure I hadn’t stuffed up the logic). Originally I was simply using FTPPutFile() but that didn’t work any better.
Latest build, run on test system:
<samp>
01/02/13 16:47:28 FTP via West Wind Web Connection 5.51
01/02/13 16:47:28 Connecting to qttest.ntl.quids.com.au as Quids\Web_Console
01/02/13 16:47:34 FTP Passive mode is On
01/02/13 16:47:34 Proxy Server is disabled
01/02/13 16:47:34 Connection Type : Direct
01/02/13 16:47:34 Connection Timeout : 25
01/02/13 16:47:34 Current folder : /
01/02/13 16:47:34 Changing current folder to incoming\
01/02/13 16:47:34 FTP Remote Folder change : Successful
01/02/13 16:47:34 Current folder : /incoming
01/02/13 16:47:34 Binary transfer is On
01/02/13 16:47:35 Uploaded 4096 bytes of 73114 bytes
01/02/13 16:47:35 Uploaded 8192 bytes of 73114 bytes
01/02/13 16:47:35 Uploaded 12288 bytes of 73114 bytes
01/02/13 16:47:35 Uploaded 16384 bytes of 73114 bytes
01/02/13 16:47:35 Uploaded 20480 bytes of 73114 bytes
01/02/13 16:47:35 Uploaded 24576 bytes of 73114 bytes
01/02/13 16:47:35 Uploaded 28672 bytes of 73114 bytes
01/02/13 16:47:35 Uploaded 32768 bytes of 73114 bytes
01/02/13 16:47:35 Uploaded 36864 bytes of 73114 bytes
01/02/13 16:47:35 Uploaded 40960 bytes of 73114 bytes
01/02/13 16:47:35 Uploaded 45056 bytes of 73114 bytes
01/02/13 16:47:35 Uploaded 49152 bytes of 73114 bytes
01/02/13 16:47:35 Uploaded 53248 bytes of 73114 bytes
01/02/13 16:47:35 Uploaded 57344 bytes of 73114 bytes
01/02/13 16:47:35 Uploaded 61440 bytes of 73114 bytes
01/02/13 16:47:35 Uploaded 65536 bytes of 73114 bytes
01/02/13 16:47:35 Uploaded 69632 bytes of 73114 bytes
01/02/13 16:47:35 Uploaded 73114 bytes of 73114 bytes
01/02/13 16:47:35 Uploaded 0 bytes of 73114 bytes
01/02/13 16:47:35 Transferred r:\dilbert\173028.strip.print.gif to incoming\
</samp>
Main Code :
defineclass FTPAction as action_q of ds_action.prg nResult= 0function process () as integer*: Overwritten to allow a numeric result to be passed backlocal nResult, cFileList, ii, oFTP, cFile, nFiles, lConnected, ; cFTPServer, cFTPUser, cFTPPwd, cFTPRemoteDir, nFileResult nResult= 0 lConnected= .f. oFTP= newoFTP() withthis .cStatus = "FTP via West Wind Web Connection " + transform(oFTP.cVersion)* Find the files to send cFileList= .Args("Files")* First check that each file exists nFiles= iif(empty(m.cFileList), 0, getwordcount(m.cFileList, ","))if m.nFiles = 0 .cStatus= "No files specified in FILES parameter" nResult= 1elsefor ii= 1 to m.nFiles cFile= alltrim(getwordnum(m.cFileList, m.ii, ","))if ! file(m.cFile) .cStatus= "Cannot locate file " + ltrim(str(m.ii)) + " <" + m.cFile + ">" nResult= 1endifendforendifif m.nResult = 0* Ok, all the files exist. Connect to the remote FTP server. cFTPServer= .Args("Server")ifempty(m.cFTPServer) cFTPServer= oG.iniRead("FTP Server")endif cFTPUser= .Args("Username")ifempty(m.cFTPUser) cFTPUser= oG.iniRead("FTP Username")endif cFTPPwd= .Args("Password")ifempty(m.cFTPPwd) cFTPPwd= oG.iniRead("FTP Password")endif cFTPRemoteDir= addbs(.Args("RemoteDir")) oFTP.cErrorMsg= "" .cStatus= "Connecting to " + m.cFTPServer + " as " + m.cFTPUser nResult= oFTP.ftpconnect(m.cFTPServer, m.cFTPUser, m.cFTPPwd)if m.nResult # 0 .cStatus= "Could not connect to server " + m.cServer ; + ", Error Code : " + ltrim(str(m.nResult))else lConnected= .t. .cStatus= "FTP Passive mode is " + iif(oFTP.lPassiveFtp, "On", "Off")if oFTP.lPassiveFtp* jic the connection has to be open first oFTP.lPassiveFtp= .t.endififempty(oFTP.cHTTPProxyName) .cStatus= "Proxy Server is disabled"else .cStatus= "Proxy Server is set to <" + oFTP.cHTTPProxyName + ">" .cStatus= "Proxy Username is set to <" + oFTP.cHTTPProxyUsername + ">"endif .cStatus= "Connection Type : " + icase(oFTP.nHTTPConnectType = 0, "IE Settings", ; oFTP.nHTTPConnectType = 1, "Direct", "Proxy") .cStatus= "Connection Timeout : " + ltrim(str(oFTP.nConnectTimeout))endifif !empty(oFTP.cErrorMsg) .cStatus= "FTP Message : " + oFTP.cErrorMsgendifendifif m.nResult = 0 .cStatus= "Current folder : " + oFTP.FTPGetCurrDir() .cStatus= "Changing current folder to " + m.cFTPRemoteDir .cStatus= "FTP Remote Folder change : " + iif(oFTP.FTPSetCurrDir(m.cFTPRemoteDir), "Successful", "Failed") .cStatus= "Current folder : " + oFTP.FTPGetCurrDir() .cStatus= "Binary transfer is " + iif(oFTP.nFTPBinary = 1, "On", "Off")bindevent(oFTP, "OnFTPBufferUpdate", this, "OnFTPBufferUpdate", 1)for ii= 1 to m.nFiles cFile= alltrim(getwordnum(m.cFileList, m.ii, ",")) oFTP.cErrorMsg= "" nFileResult= oFTP.FTPSendFileEx(m.cFile, justfname(m.cFile))if m.nFileResult = 0 .cStatus= "Transferred " + m.cFile + " to " + m.cFTPRemoteDirelse .cStatus= "Failed to transfer " + m.cFile + " to " + m.cFTPRemoteDir ; + ", Error Code : " + ltrim(str(m.nFileResult))* Returns the first non-zero error code - that's where the rot starts! nResult= evl(m.nResult, m.nFileResult)endifif !empty(oFTP.cErrorMsg) .cStatus= "FTP Message : " + oFTP.cErrorMsgendifendforendifif m.lConnected oFTP.ftpclose()endifendwithreturn m.nResultendfunc&& process()procedure OnFTPBufferUpdate (lnbytesdownloaded,lnbufferreads,lccurrentchunk, lnTotalBytes)withthis .cStatus= "Uploaded " + ltrim(str(m.lnbytesdownloaded)) + " bytes of " + ltrim(str(lnTotalBytes)) + " bytes"endwithendproc&& OnFTPBufferUpdate()enddefine
Do you have any suggestions? Are there any other utilities that I can use to check why it isn’t working? Do I need to wait until the connection is open to set the value of lPassiveFTP? As I said, I’ve tried resetting it once the connection is open but I am actually setting it in the init() of the FTP object already. Does it need to change from .f. to .t.? I’m clutching at straws there I think but I’ve run out of ideas. We run numerous FTP transfers to a variety of other businesses and none of them are working. We have monitored the other end of the transfers and the remote file is initially created (0 bytes) but no data seems to actually be transferred.
Hoping you have more idea than I do. Thanks,
Rob Spencer