FTP trouble uploading files/renaming folders
Ben Rubinstein
benr_mc at cogapp.com
Tue Mar 7 00:37:35 EST 2006
Abstract: I've encountered two different problems uploading data over FTP - if
I could solve either of them, I'd have a working solution. One applies only
on Windows, the other on both Mac and Windows - both seem to be independant of
the destination FTP server.
I'm trying to code a utility that needs to upload a folder of files to an FTP
server. This has been well tested without any problems on Mac; on Windows,
however, I've run into a problem.
The basic sequence is:
- check if the destination folder exists
- if it doesn't, create it, upload all the files to it
- if it does, then
- create a temporary folder
- upload all the files to the temporary folder
- rename the existing folder to a backup
- rename the temporary folder
The method of uploading files has essentially been
put URL ("binfile:/xxxx") into URL ("ftp://xxx")
This works fine on Mac, given due attention to active/passive mode and timeout
settings; against a variety of Unix and Windows FTP servers.
On Windows (tested on Windows XP and Windows 2000) there's a consistent
result: the app can succesfully list directories and when necessary create
directories; when it comes to upload the file, however, the put command
returns with the result "requested".
It doesn't time out - the pattern is that a "STOR" command is isssued, the
server responds with either "150 Opening BINARY mode data connection for xxx",
or "125 Data connection already open; Transfer starting." (these are from two
different servers, one IIS on Windows, one ProFTPD on Unix). In both cases
that's exactly what is seen when Revolution is running on Mac also. However,
whereas on Mac this is then followed by a "226 Transfer complete", on Windows
the pattern seems to be a 'FIN ACK' packet, followed by an 'ACK', then a 'RST
ACK' - and the command returns "requested". This happens immediately - it's
not related to the current timeout setting.
I could reproduce this with a trivial stack simply doing the one-off "put URL
binfile:x into URL ftp:y". command - it didn't need my full app doing it's
full thing to display exactly this behaviour. The same result also was
obtained by splitting the task into two statements: "put URL binfile:x into z;
put z into URL ftp:y".
The files involved are just a few K; however, as an experiment, I tried
replacing the above statements with a "libURLftpUploadFile" command. It
worked! So I made this change in my app.
Now the results are the same on both Mac and Windows. In both cases, the
files are uploaded OK; but after all the files have been uploaded, the
*unchanged* code for renaming the folders fails. The results are the same
whether Revolution is running on Mac or Windows; but they differ according to
the server. The rename folder code executes a pair of libURLftpCommand
statements, a "RNFR" and a "RNTO". In all cases (and this is presumably the
root of the problem) Revolution attempts to log into the FTP server again to
issue these commands, whereas when libURLftpUploadFile was not used, the
connection from the file uploads is also used for these commands. The IIS FTP
server responds to the second log-in attempt by asking for the username and
password, then reporting that the user cannot log in. The Unix FTP server
allows the second connection, accepts the RNFR command with "350 file exists",
but responds to the "RNTO" command with "503 Bad sequence of commands". Then
both connections are closed.
So in summary:
1) doing
put x into URL "ftp://y"
works when Rev is on Mac, fails when Rev is on Windows.
2) Using libURLftpUploadFile works on both platforms - but attempting to use
libURLftpCommand immediately after a sequence of libURLftpUploadFile
statements tries to open another connection, with unfortunate consequences.
Can anyone shed light on either of these problems? Has anyone encountered
similar problems; or conversely, attempted similar tasks without encountering
such problems?
This is all in Rev 2.6.1, btw, with libURL 1.1.4.
TIA,
Ben Rubinstein | Email: benr_mc at cogapp.com
Cognitive Applications Ltd | Phone: +44 (0)1273-821600
http://www.cogapp.com | Fax : +44 (0)1273-728866
More information about the use-livecode
mailing list