- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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):
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
How do you know which is the latest file? Does your prefix/naming convention include the date?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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