header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
Easy FTP in Powershell
Last Post 03 Sep 2010 09:59 AM by Tom2112. 0 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
Tom2112User is Offline
New Member
New Member
Posts:8
Avatar

--
03 Sep 2010 09:59 AM
    I've been searching for a very simple method of FTP-ing a file from within Powershell. My search came up with a lot of complex answers, which I'm sure have their place. However, I was looking for the simplest way to just grab a file via FTP from a server that requires a username and password.

    It turns out you can simply rely on Windows native FTP client. The ftp command in Windows will take a -s switch with a file spec. That file needs to be a list of the responses for your ftp session. One per line and in order, just like a script.

    So to grab the file myfile.csv from the server 192.168.1.1 with a username and password of tomtom and letmein you would use this:

    ftp -s:myscript.txt 192.168.1.1

    Where the myscript.txt file would look like this:
    tomtom
    letmein
    get myfile.csv
    quit

    Yes, you can use that command straight from the powershell prompt or from a DOS prompt, assuming that your script file is in the directory that you are in at the time when its run. Of course, you can use full paths if you need to.

    Sure, I know that having my FTP username and password in a plain text file sitting on my server is a security risk. I handled that by make the privs on that account very limited. It can read-only, and only see one directory, which is where the file I need sits and nothing more. So, the risk is quite manageable. YMMV.

    I hope that helps folks that just need to grab a file quickly and easily via FTP and Powershell.
    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer