我有一个文本文件,我从批处理文件中调用它并不是在FTP站点中递归放置文件。文件夹结构具有子文件夹,其中包含我要在许多其他文件中复制的文件。 put文件仅复制C:\storage
。阅读文档后尝试其他方法仍然不是递归复制文件。 (没有从子文件夹中使用RDF复制的文件夹)
文件夹结构在不同的PC上是随机的:
有许多RDF文件,但我感兴趣的通配符是您可以在上面看到的那个。基本上我想选择所有* .RDF(作为上面所有子文件夹的通配符),但不希望将子文件夹复制到遥控器。
请参阅以下代码。
option batch continue
option confirm off
option reconnecttime 900
open ftp://companyuser:!password@ftpsite.com/
lcd "C:\storage"
put "C:\storage\78286.S-92A.920024*.RDF" "/"
put "C:\storage\*\78286.S-92A.920024*.RDF" "/"
close
exit
答案 0 :(得分:1)
仅使用WinSCP脚本进行此类自定义处理并不容易。
但使用WinSCP .NET assembly中的PowerShell script,并不困难:
# Load WinSCP .NET assembly
Add-Type -Path "WinSCPnet.dll"
# Set up session options
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
Protocol = [WinSCP.Protocol]::Ftp
HostName = "ftp.example.com"
UserName = "username"
Password = "password"
}
$session = New-Object WinSCP.Session
Write-Host "Connecting ..."
$session.Open($sessionOptions)
$localPath = "C:\storage"
$remotePath = "/"
$wildcard = "78286.S-92A.920024*.RDF"
$localFiles = Get-ChildItem -Include $wildcard -Recurse -Path $localPath
foreach ($localFile in $localFiles)
{
Write-Host "Uploading $($localFile.FullName)..."
$session.PutFiles($localFile.FullName, $remotePath).Check()
}
只需提取WinSCP .NET assembly package的内容以及脚本(例如flatupload.ps1
)并按以下方式运行:
powershell -ExecutionPolicy Bypass -File flatupload.ps1
代码部分基于WinSCP示例Recursively move files in directory tree to/from SFTP/FTP server while preserving source directory structure。
答案 1 :(得分:0)
查看https://winscp.net/eng/docs/commandline
上的文档您可以使用命令行winscp.com
您的脚本似乎很好,需要使用winscp.com
对于Linux上的ftp客户端,mput / mget(多文件操作),命令可用但WinScp不可用。
您可以尝试使用mkdir命令(使用winscp.com)首先创建文件夹,然后使用synchronize
选项和winscp.exe
来更新文件夹内容。