1

I am trying to figure out how to use this PSFTP module I downloaded from Microsoft. I want to download the entire ftp directory recursively with all directories to my local machine. Has anyone had success doing this and can you share your script? Thanks!


Edit:

ContentLength           : -1
Headers                 : {}
SupportsHeaders         : True
ResponseUri             : ftp://ftp.xxxxxxxxxxxxxxxxxxx.com/
StatusCode              : ClosingData
StatusDescription       : 226-Options: -a -l 
                          226 140 matches total

LastModified            : 1/1/0001 12:00:00 AM
BannerMessage           : 220---------- Welcome to Pure-FTPd     
[privsep]     [TLS] ----------
                      220-You are user number 1 of 500 allowed.
                      220-Local time is now 19:22. Server port: 21.
                      220-This is a private system - No anonymous login
                      220 You will be disconnected after 3 minutes of 
inactivity.

WelcomeMessage          : 230 OK. Current restricted directory is /

ExitMessage             : 221-Goodbye. You uploaded 0 and downloaded 0 
kbytes.
                          221 Logout.                          
IsFromCache             : False
IsMutuallyAuthenticated : False
ContentType             :

And the script:

Import-Module PSFTP
$FTPServer = 'ftp.xxxxxxxxxxxxxxxx.com'
$FTPUsername = 'xxxxxxxxxxxx'
$FTPPassword = 'xxxxxxxxxxxxxxxxxxxx'
$FTPSecurePassword = ConvertTo-SecureString -String $FTPPassword -asPlainText -Force
$FTPCredential = New-Object System.Management.Automation.PSCredential($FTPUsername,$FTPSecurePassword)
Set-FTPConnection -Credentials $FTPCredential -Server $FTPServer -Session MySession -UsePassive 
$Session = Get-FTPConnection -Session MySession 
Get-FTPChildItem -Session $Session -Path / -Recurse

Remediated Code:

$Session = Get-FTPConnection -Session MySession 
$FTPCredential = New-Object System.Management.Automation.PSCredential($FTPUsername,$FTPSecurePassword)
Set-FTPConnection -Credentials $FTPCredential -Server $FTPServer -Session
$Session -UsePassive 
Get-FTPChildItem -path $FTPServer -Session $Session -Recurse | Get-FTPItem -localpath C:\sitebackups\ -RecreateFolders -Verbose
2
  • Have you tried anything? Commented Jan 6, 2017 at 2:02
  • 1
    [psftp] is not an appropriate tag here. "psftp" has been the PuTTY command-line tool for at least a decade before Powershell existed. Commented Jan 6, 2017 at 2:03

1 Answer 1

1

Is this what you want?

Get-FTPChildItem -path ftp://test.net/ftpfolder/test -Recurse | Get-FTPItem -localpath C:\Users\test\Downloads\ -RecreateFolders -Verbose

Test:

PS C:\Users\test> Get-FTPChildItem -path ftp://test.net/ftpfolder/test -Recurse | Get-FTPItem -localpath C:\Users\test\Downloads\ -RecreateFolders -Verbose
VERBOSE: Performing the operation "Download item:
'ftp://test.net/ftpfolder/test/folder1'" on target "".
VERBOSE: Performing the operation "Download item:
'ftp://test.net/ftpfolder/test/folder2'" on target "".
VERBOSE: Performing the operation "Download item:
'ftp://test.net/ftpfolder/test/file1.zip'" on
target "".
VERBOSE: Creating folder: ftpfolder\test\
226 Transfer complete.

VERBOSE: Performing the operation "Download item:
'ftp://test.net/ftpfolder/test/folder1/event_page.zip'"
on target "C:\Users\test\Downloads\event_page.zip".
VERBOSE: Creating folder: ftpfolder\test\folder2
226 Transfer complete.

You can find more examples from PSFTP/Get-FTPItem.ps1

.EXAMPLE    
    PS P:\> Get-FTPChildItem -path folder/subfolder1 -Recurse | Get-FTPItem -localpath p:\test -RecreateFolders -Verbose
    VERBOSE: Performing operation "Download item: 'ftp://ftp.contoso.com/folder/subfolder1/test.xlsx'" on Target "p:\test\folder\subfolder1".
    VERBOSE: Creating folder: folder\subfolder1
    226 File send OK.

    VERBOSE: Performing operation "Download item: 'ftp://ftp.contoso.com/folder/subfolder1/ziped.zip'" on Target "p:\test\folder\subfolder1".
    226 File send OK.

    VERBOSE: Performing operation "Download item: 'ftp://ftp.contoso.com/folder/subfolder1/subfolder11/ziped.zip'" on Target "p:\test\folder\subfolder1\subfolder11".
    VERBOSE: Creating folder: folder\subfolder1\subfolder11
    226 File send OK.
Sign up to request clarification or add additional context in comments.

7 Comments

Ok, I'll give that a go and let you know either way, thanks!
Ok, tried that and FTP gave me this error: WARNING: Add-FTPItem: Cannot find session DefaultFTPSession. First use Set-FTPConnection to config FTP connection.
It would appear this FTP site is using TLS; how would I go about making the script handle that?
@bbcompent1 with -EnableSsl -ignorecert option. For details, you can refer to PSFTP\Set-FtpConnection.ps1.
@bbcompent1 Set-FTPConnection -Credentials $Credentials -Server myftpserver.com -EnableSsl -ignoreCert -UsePassive
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.