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
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.
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
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?
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.
If you have EG you can use this add in:
http://blogs.sas.com/content/sasdummy/2012/12/06/copy-files-in-sas-eg/
PROC DOWNLOAD if you have the license for SAS/CONNECT
http://www2.sas.com/proceedings/sugi30/023-30.pdf (top of page 6)
Google search results (untested):
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.
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.
How do you know which is the latest file? Does your prefix/naming convention include the date?
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.
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.
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
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.