我正在尝试制作批处理文件以将文件上传到ftp服务器.如果我手动输入它可以正常工作,但是当我运行批处理文件时,它会在连接后暂停...它说
connected to domain.com.
220 microsoft ftp server
User(domain.com:(none)):
Run Code Online (Sandbox Code Playgroud)
没什么别的.到底发生了什么事?
以下是我的批处理文件:
ftp www.domainhere.com
user useridhere
passwordhere
put test.txt
bye
pause
Run Code Online (Sandbox Code Playgroud) 我想使用PowerShell自动化FTP下载数据库备份文件.文件名包含日期,因此我不能每天运行相同的FTP脚本.是否有一种干净的方法来构建PowerShell或使用.Net框架?
更新我忘了提到这是一个通过安全的FTP会话.
我需要一些指导.我需要在C#中开发一个可自定义的FTP,它应该使用App.Config文件进行配置.此外,FTP应该再次从任何客户端将数据推送到任何服务器依赖于配置文件.
如果有人可以指导,如果有任何API或任何其他有用的建议,或者让我朝着正确的方向前进,我将不胜感激.
我正在尝试使用psftp.exe(putty)从PowerShell SFTP文件.我可以运行单个命令,如open,但我需要更改默认目录然后放入文件.以下代码将我带到psftp但忽略了从cd ..到bye的行.我想我可以运行一个具有sftp命令的批处理文件但是如果可能的话我想用PowerShell完成.
$file = "C:\Source\asdf.csv"
$user = "user"
$pass = "pass"
$hst = "host"
$path="C:\ProgramFiles\psftp.exe"
$cmd = @"
-pw $pass $user@$hst
cd ..
cd upload
put $file
bye
"@
invoke-expression "$path $cmd"
Run Code Online (Sandbox Code Playgroud) Windows中的certutil可用于执行Base64编码和解除.是否有用于URL编码和解码的内置实用程序?网上有很多免费工具.但我特意寻找Windows内置实用程序或者不是可以在Windows上运行的简单脚本.
谢谢!
我正在使用PowerShell脚本将整个文件夹的内容上传到FTP位置.我对PowerShell很新,只有一两个小时的经验.我可以得到一个文件上传很好,但找不到一个很好的解决方案,为文件夹中的所有文件.我假设一个foreach循环,但也许有更好的选择?
$source = "c:\test"
$destination = "ftp://localhost:21/New Directory/"
$username = "test"
$password = "test"
# $cred = Get-Credential
$wc = New-Object System.Net.WebClient
$wc.Credentials = New-Object System.Net.NetworkCredential($username, $password)
$files = get-childitem $source -recurse -force
foreach ($file in $files)
{
$localfile = $file.fullname
# ??????????
}
$wc.UploadFile($destination, $source)
$wc.Dispose()
Run Code Online (Sandbox Code Playgroud) 我正在使用以下脚本文件 (ftp_test_2.ps1) 将文件传输到 ftp 服务器:
#we specify the directory where all files that we want to upload are contained
$Dir="C:/Users/you-who/Documents/textfiles/"
#ftp server
$ftp = "ftp://192.168.100.101:21/"
$user = "aP_RDB"
$pass = "pw"
$webclient = New-Object System.Net.WebClient
$webclient.Credentials = New-Object System.Net.NetworkCredential($user,$pass)
#list every txt file
foreach($item in (dir $Dir "*.txt"))
{
"creating URI..."
$uri = New-Object System.Uri($ftp+$item.Name)
$uri
"attempting upload... $item"
$webclient.UploadFile($uri, $item.FullName)
}
Run Code Online (Sandbox Code Playgroud)
当 $ftp 设置为本地主机并连接到另一个 ftp 测试服务器时,这可以正常工作。但是,在生产 ftp 服务器上,服务器拒绝上传并显示 Powershell 错误:
Exception calling "UploadFile" with "2" argument(s): "The remote server …Run Code Online (Sandbox Code Playgroud) powershell ×5
ftp ×4
.net ×3
command-line ×2
c# ×1
url-encoding ×1
urldecode ×1
urlencode ×1
webclient ×1
windows ×1
winforms ×1