PowerShell连接到FTP服务器并获取文件

PowerShell连接到FTP服务器并获取文件

本文介绍了PowerShell连接到FTP服务器并获取文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$ftpServer = "ftp.example.com"
$username ="validUser"
$password ="myPassword"
$localToFTPPath = "C:\ToFTP"
$localFromFTPPath = "C:\FromFTP"
$remotePickupDir = "/Inbox"
$remoteDropDir = "/Outbox"
$SSLMode = [AlexPilotti.FTPS.Client.ESSLSupportMode]::ClearText
$ftp = new-object "AlexPilotti.FTPS.Client.FTPSClient"
$cred = New-Object System.Net.NetworkCredential($username,$password)
$ftp.Connect($ftpServer,$cred,$SSLMode) #Connect
$ftp.SetCurrentDirectory($remotePickupDir)
$ftp.GetFiles($localFromFTPPath, $false) #Get Files

这是我从FTP服务器导入文件的脚本。 $ b但是我不确定什么是 remotePickupDir 并且这个脚本是否正确?

This is the script I got for importing files from an FTP server.
However I am not sure what is the remotePickupDir and is this script correct?

推荐答案

远程挑选目录路径应该是您尝试访问的ftp服务器上的确切路径。是从服务器下载文件的脚本..
可以使用SSLMode添加或修改..

Remote pick directory path should be the exact path on the ftp server you are tryng to access..here is the script to download files from the server..you can add or modify with SSLMode..

#ftp server
$ftp = "ftp://example.com/"
$user = "XX"
$pass = "XXX"
$SetType = "bin"
$remotePickupDir = Get-ChildItem 'c:\test' -recurse
$webclient = New-Object System.Net.WebClient

$webclient.Credentials = New-Object System.Net.NetworkCredential($user,$pass)
foreach($item in $remotePickupDir){
    $uri = New-Object System.Uri($ftp+$item.Name)
    #$webclient.UploadFile($uri,$item.FullName)
    $webclient.DownloadFile($uri,$item.FullName)
}

这篇关于PowerShell连接到FTP服务器并获取文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 15:28