Help using Base SAS procedures

Transfer a zip file from other server to sas sftp server

Reply
SAS Employee
Posts: 17

Transfer a zip file from other server to sas sftp server

Dear ,

I am using this code to transfer a zip file from other server to sas sftp server.
But I am getting a corrupted file.
Please help me.

data _null_ ;
X 'umask 0000';
run;

x '@echo off';
x 'cd ';
x 'echo open > b.ftp';
x 'echo user user pwd >> b.ftp' ;

x "echo cd b.ftp";
x 'echo asc >> b.ftp';
x "echo get 6546_file.zip >> b.ftp";

x 'echo bye >> b.ftp ';
x 'ftp -ni <<destination_location>b.ftp > b.ftplog';

x 'echo bye';
Frequent Contributor
Frequent Contributor
Posts: 94

Re: Transfer a zip file from other server to sas sftp server

You might try specifying binary transfer mode before moving any of the files? Just send the command "bin" in the same way you have done so for the others.
SAS Employee
Posts: 17

Re: Transfer a zip file from other server to sas sftp server

Dear DF,

Can you please alloborate some more as I am a new to programming.
Frequent Contributor
Frequent Contributor
Posts: 94

Re: Transfer a zip file from other server to sas sftp server

Sure - sorry if I was a bit too vague!

You have a line in your code that reads:

x 'echo asc >> b.ftp';

The "asc" tells FTP to transfer the file in ASCII mode. This works for text files like CSV or .tab, etc. and will automatically translate between Windows and UNIX text formats (for example).

However a ZIP file is not a text file, so this reformatting will corrupt the file. Try changing it instead to be:

x 'echo bin >> b.ftp';

That should tell it to copy in binary mode, and should hopefully stop your file corruption.

This article has some good notes on the subject: http://www.remote-control.net/articles/2006/ftp_notes/

Hope that helps!
Ask a Question
Discussion stats
  • 3 replies
  • 287 views
  • 0 likes
  • 2 in conversation