gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 21:08:59 30 4
gpt4 key购买 nike

$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服务器导入文件的脚本。
但是我不确定 remotePickupDir是什么,此脚本正确吗?

最佳答案

远程选择目录路径应该是您尝试访问的ftp服务器上的确切路径。
这是从服务器下载文件的脚本。
您可以使用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 - PowerShell连接到FTP服务器并获取文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19059394/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com