在此找不到太多信息!尽管上面提供了凭据,但远程服务器返回错误(530)尚未登录。不确定我要去哪里哪里-Powershell新手在这里。任何帮助表示赞赏。
# FTP CREDENTIALS
$FTPUsername = "USER"
$FTPPassword = "PASSWORD"
$FTPHost = "ftp://FTPURI.net"
$FTPSecurePassword = ConvertTo-SecureString -String $FTPPassword -asPlainText -Force
$FTPCredentials = New-Object System.Net.NetworkCredential($FTPUsername,$FTPSecurePassword)
#Start FTP Webrequest and configure
$ftp=[System.Net.FtpWebRequest]::Create("$FTPHost")
$ftp.Credentials=$FTPCredentials
$ftp.UseBinary = $true
$ftp.UsePassive = $true
#Folder with new ESL
$NewESLDir = "\\egregorio\Staging\ESLOffice3.17\Release Candidate\Codebase\wwwroot"
#FTP Directory to upload Files
$destination = "ftps:/**********@***********/site/TESTING"
#Create WebClient
$webclient = New-Object -TypeName System.Net.WebClient
$webclient.Credentials = New-Object System.Net.NetworkCredential($FTPUsername,$FTPSecurePassword)
#Define which files/ folders we are to upload
$Entries = Get-ChildItem $NewESLDir -Recurse
$Folders = $Entries | Where-Object{$_.PSIsContainer}
$Files = $Entries | Where-Object{!$_.PSIsContainer}
# Create Directories in FTP if needed (help me please)
foreach ($folder in $Folders)
{
$FolderPath = $NewESLDir -replace "\\","\\" -replace "\:","\:"
$DesFolder = $folder.Fullname -replace $FolderPath,$FTPHost
$DesFolder = $DesFolder -replace "\\", "/"
# Write-Output $DesFolder
try
{
$makeDirectory = [System.Net.WebRequest]::Create($DesFolder);
$makeDirectory.Credentials = New-Object System.Net.NetworkCredential($FTPUsername,$FTPSecurePassword);
$makeDirectory.Method = [System.Net.WebRequestMethods+FTP]::MakeDirectory;
$makeDirectory.GetResponse();
#folder created successfully
}
catch [Net.WebException]
{
try {
#if there was an error returned, check if folder already existed on server
$checkDirectory = [System.Net.WebRequest]::Create($DesFolder);
$checkDirectory.Credentials = New-Object System.Net.NetworkCredential($FTPUsername,$FTPSecurePassword);
$checkDirectory.Method = [System.Net.WebRequestMethods+FTP]::PrintWorkingDirectory;
$response = $checkDirectory.GetResponse();
#folder already exists!
}
catch [Net.WebException]
{
#if the folder didn't exist
}
}
}
# Upload Files - Start
foreach($entry in $Files)
{
$Fullname = $entry.fullname
$Name = $entry.Name
$FilePath = $UploadFolder -replace "\\","\\" -replace "\:","\:"
$DesFile = $Fullname -replace $FilePath,$FTPHost
$DesFile = $DesFile -replace "\\", "/"
# Write-Output $DesFile
$uri = New-Object System.Uri($DesFile)
$webclient.UploadFile($uri, $Fullname)
}
# Upload Files - Stop
您可以看到上面输入了我的凭据,这在第76行出现了错误( “ $ webclient.UploadFile($ uri,$ Fullname)”),但我上面我输入了webclient.credentials,因此我不确定何时未登录。这是我第一次发布到堆栈溢出,我只是出于绝望而这样做!抱歉