FTP Scripting Standards?

Status
Not open for further replies.

Jonno

Ars Scholae Palatinae
972
Hi,

are there and standards for writing scripts for automating FTP sessions?

Reason I ask is at work we have an issue with our (outsourced) IT guys FTPing files to our (outsourced) printing suppliers and I don't know who, if anyone, is to blame.

Is there an accepted way of dealing with interrupted sessions (due to connection problems for example)?

This is the redacted and shortened log from our end of the transfer.

Code:
Attempt 1.... (several files already transferred OK at this point) 
Starting request
Opening remote file "[directory redacted]20141203_020022.27_CL01.zip" for writing 
Uploading local file "[directory redacted]20141203_020022.27_CL01.zip"
# transferred 2106963 bytes in 0.577 seconds, 29202.486 kbps ( 3650.311 kBps), transfer succeeded.
Opening remote file [directory redacted]020343.51_CL01.zip" for writing
Uploading local file "[directory redacted]020343.51_CL01.zip"
# transferred 2357980 bytes in 0.515 seconds, 36642.982 kbps ( 4580.373 kBps), transfer failed.

(IT say at this point the script terminated)

Attempt 2....
Starting request
Opening remote file "[directory redacted]20141203_020022.27_CL01.zip" for writing
Permission denied: Permission denied (IT say this was expected as file is there already)
Opening remote file [directory redacted]20141203_020343.51_CL01.zip" for writing
Permission denied: Permission denied (IT say this was unexpected, as the file failed to transfer 
in earlier attempt. I think the script terminated at this point but IT haven't said for 
definite and I don't have the complete log)

Attempt 3.....
Starting request
Opening remote file "[directory redacted]20141203_020022.27_CL01.zip" for writing
Uploading local file "[directory redacted]20141203_020022.27_CL01.zip"
# transferred 2106963 bytes in 0.546 seconds, 30871.202 kbps ( 3858.900 kBps), transfer succeeded.
(IT say this was unexpected, as this file is already there.)
Opening remote file "[directory redacted]20141203_020343.51_CL01.zip" for writing
Uploading local file "[directory redacted]20141203_020343.51_CL01.zip"
# transferred 8540419 bytes in 1.732 seconds, 39456.705 kbps ( 4932.088 kBps), transfer succeeded. 
(IT says this was expected)

The file names change daily and include the date.

Is IT's script making dangerous assumptions or is it simply not clever enough? Should it be checking if files to exist before it transfers them? Should it not be trying to transfer files it's already sent, ie not relying on the receiving server to reject existing files?

This is why I ask if there's a standard protocol for FTP scripting and the assumptions it safe to make about the other servers behaviour.
 
I don't know about standards, but in this situation I would upload a temporary file (using a naming pattern that the customer will not consume) and rename it to the final name when it is complete. This will prevent premature or incomplete consumption (assuming atomic rename at the destination).

After a successful rename I'd mark it as transmitted on my end (delete the local file or whatever), but you could check for the final name before you start too.
 

dredphul

Ars Tribunus Angusticlavius
6,349
Subscriptor++
Do you have a copy of the script to examine?

Are they setting binary mode before trying to upload the zip files?

Do you know what ftp server and ftp client are being used?

The ftp standard is extremely loose and ambiguous. I've had a case where a particular combination of ftp server and client just would not work properly. After switching to a different ftp client, the uploads worked fine.
 

Jonno

Ars Scholae Palatinae
972
I believe our IT is using Ipswich sFTP.

I thought everyone writing new scripts would be using Kermit by now.

ars.mrp that's exactly what I'd expect them to do but it seems they are doing nothing like that at all. Just uploading the final filename to the final directory.

Don't have a copy of the script but we spoke to them today and they agreed their script is too simple and lacks the necessary sophistication to cope with a dropped connection so they are re-writing it.

Additionally they are not always sending it before the agreed time, or very close to it because in-house processing isn't complete. So the printers watcher service could be grabbing the file before it's even complete. So they've agree to push back their time as well.
 

Nimdok

Ars Scholae Palatinae
1,214
At my last company we had an entire team devoted to handling all the piles of file transfers that were needed. There were quirks for every vendor. SSH, SFTP, FTP, FTP w/PGP, HTTPS... Perl and curl in verbose debug mode are useful tools in this domain.

For FTP, definitely have them implement the atomic rename as ars.mrp suggests, or a checksum or signature file or something.

I wouldn't say anyone is to blame, but you have to give someone the responsibility to make it all work. I'd say the onus is on the IT group to make it work, with the caveat that the printing group has to provide a working sample script and some details about their platform.

It'd probably be easiest to write the code yourself and email it to them. :)
 
Status
Not open for further replies.