通过 PowerShell 自动上传 SSL FTP [英] Automate SSL FTP upload via PowerShell

查看:72
本文介绍了通过 PowerShell 自动上传 SSL FTP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经搜索并阅读了很多关于在 PowerShell 中下载 SSL FTP 文件的内容...但是我该如何上传它们呢?我有一个每天需要上传的文件名,但我收到了我未登录的错误.我目前正在像这样上传到其他 FTP 站点:

I have searched and read a lot about downloading SSL FTP files in PowerShell... But how do I upload them? I have a filename I need to upload each day and I get errors that I am not logged in. I'm currently uploading to other FTP sites like this:

$Filename = "myfile.txt"
$FullPath = "\\server\share\$Filename"
$ftp = "ftp://user:pass@ftp.domain.com/$Filename"
$ftpWebClient = New-Object System.Net.WebClient
$ULuri= New-Object System.URI($ftp)
$ftpWebClient.UploadFile($ULuri, $FullPath)

我是否需要为 SSL FTP 上传创建一个全新的代码块,或者我只需要对此代码进行细微调整?

Do I need to create a whole new block of code for the SSL FTP upload, or do I just need to make minor adjustments to this code?

谢谢!

推荐答案

我使用 WinSCP DLL 来做这些事情.在此处查看一些示例:http://winscp.net/eng/docs/library#powershell

I use the WinSCP DLL to do this stuff. Check out some examples here: http://winscp.net/eng/docs/library#powershell

这是我的一些示例代码.

Here's some of my sample code.

[Reflection.Assembly]::LoadFrom("D:\WinSCP.dll") | Out-Null
$sessionOptions = New-Object WinSCP.SessionOptions
$sessionOptions.Protocol = [WinSCP.Protocol]::Sftp
$sessionOptions.HostName = "192.168.1.120"
$sessionOptions.UserName = "user"
$sessionOptions.Password = "pass"
$session = New-Object WinSCP.Session
$session.Open($sessionOptions)

#upload stuff here, check the link for detail on how, and use powershell to populate your file list!

$session.Dispose()

这篇关于通过 PowerShell 自动上传 SSL FTP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆