BookmarkSubscribeRSS Feed
nikunjgattani
Obsidian | Level 7

Hi,

 

I want to copy a file from FTP server (Unix) to local machine (Windows) using SAS code.

 

There are many files loaded in FTP server daily. So, I want just to copy the latest file from FTP to local machine.

 

Currently, I have to manually copy from Unix server to Windows using FTP (Tectia).

 

Thanks

Nikunj

12 REPLIES 12
Reeza
Super User

If you can create a script on Windows or Unix side to do the job, its relatively easy to execute the script from SAS. 

 

That's probably the ideal solution. You can also pass unix commands directly to the server or windows so if you can utilize x command you can pass the unix command to download the data as well.

 

In SAS 9.4+ there's FCOPY which will move files.

http://support.sas.com/documentation/cdl/en/lefunctionsref/67960/HTML/default/viewer.htm#n10dz22b5ix...

 

 

nikunjgattani
Obsidian | Level 7

Hi Reeza,

 

Thank You.

 

If possible, could you provide me unix code as i am not good with Unix.

So that I can make changes accordingly on that code and try it.

 

Regards,

Nikunj

Reeza
Super User

Sorry, I'm not great with Unix. It's also dependent on your application. 

 

I'm sure if you searched on StackOverflow you'd find examples of what the commands should look like. 

 

Would FCOPY work for you? Does your Base SAS see your server and your desktop at the same time? Or do you not have SAS 9.4?

Kurt_Bremser
Super User

Windows ftp can be scripted with the -s:scriptfile commandline option.

Since you will only use the Windows client, no UNIX knowledge apart from file/pathnames is required.

LinusH
Tourmaline | Level 20
And there's also the filename ftp engine.
Data never sleeps
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,

 

Why would you need to do it in SAS?  You have an FTP program, just script it within that, then schedule that script to run as and when you need.  Including another application (SAS) in the process just means another step which needs documenting, creating, and validating.  

nikunjgattani
Obsidian | Level 7

I agree with you RW9.

 

Even I tried the following code and create a batch of it for testing.

 

scpg3 host_server_name:/home/abcd/test.txt C:\abcd\Desktop

 

But, the issue is there are lot of files in the unix folder. I want the latest uploaded file only and with particular prefix.

 

Do you have any code for the same.

Reeza
Super User

How do you know which is the latest file? Does your prefix/naming convention include the date? 

nikunjgattani
Obsidian | Level 7

Hi Reez,

 

Yes prefix has date stamp.

 

Also, if possible, we can get the modification time of the file. If it is of today then we will copy it.

nikunjgattani
Obsidian | Level 7

Thanks all for your help and quick responses.

I have prepared a scp command line code. Also, files which i wanted to download has date prefix.. so that will also help me to copy the desired files only.

THANKS ALL again for their valuable advice.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Its quite dependant on what you are using as the FTP software.  I did it many years back in Reflections - VB scripting, so thats not going to be much help.  

Google throws up a lot of results, this one for instance:

http://www.dreamincode.net/forums/topic/350239-download-last-modified-file-from-ftp-server/

Or WinSCP:

https://winscp.net/eng/docs/script_download_most_recent_file

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 12 replies
  • 7370 views
  • 5 likes
  • 5 in conversation