2013-04-11 122 views
0

所以....我已經在這裏拼湊了一些其他帖子的腳本,但我還有2個剩餘的問題,我似乎無法弄清楚。第一個問題是文件超過2MB時上傳失敗。它似乎超時了,我不知道爲什麼。有沒有更好的方式來上傳大約8-12 MB的文件?第二個問題(不是一個真正的大問題)是如何更改目錄以上傳文件。我有一個場景,默認FTP ROOT目錄是/安,我需要FTP到/。有可能登錄,然後CD /?通過Powershell從.csv輸入FTP上傳

en# This script is to upload firmware to various IP Addresses in the Avaya sytem(s) 

    #Prompt the user for the ftp username and password 
     $ftp_username = Read-Host "What is the ftp username" 
     $ftp_password = Read-Host "What is the ftp password" 

    #Define and read in the .csv file 
     $importlist = import-csv c:\firmware-updates.csv 

    # This is where we start the loop 
     foreach($upload in $importlist) 
    { 
    # Define varaibles from the import file.  
     $board = $upload.Board 
     $firmware = $upload.Firmware 
     $IPaddress = $upload.IP 

    # create the FtpWebRequest and configure it 
$ftp = [System.Net.FtpWebRequest]::Create("ftp://$IPaddress/$firmware") 
$ftp = [System.Net.FtpWebRequest]$ftp 
     # Set the FTP method (upload/download) 
$ftp.Method = [System.Net.WebRequestMethods+Ftp]::UploadFile 
    # Pass the username and password to the server 
$ftp.Credentials = new-object System.Net.NetworkCredential("$ftp_username","$ftp_password") 
    # Set the modes 
$ftp.UseBinary = $true 
$ftp.UsePassive = $true 
    # read in the file to upload as a byte array 
    # Original Byte Array caused memorey error 
    #$content = [System.IO.File]::ReadAllBytes("C:\$firmware") 
$content = gc -en Byte ("C:\$firmware") 
$ftp.ContentLength = $content.Length 
    # get the stream request 
$rs = $ftp.GetRequestStream() 
$rs.Write($content, 0, $content.Length) 
echo "File $firmware is being upoaded to $IPaddress for board $board" 
    # clean up after ourselves 
$rs.Close() 
$rs.Dispose() 
$firmware.Close() 
} 
+0

2MB是一個常見的默認文件大小限制,檢查您的主機配置 – 2013-04-11 20:47:10

回答

0

我在使用Powershell和FTP之前遇到了問題,我使用了在Technet上找到的模塊。下載並導入通常的方式,一切都很好。

LINK

我沒有寫這個模塊,一切歸功於作者。

+0

魔獸......本週飛過!感謝AndyMeful,我會嘗試一下,看看我能否實現它 – hotch 2013-04-19 01:29:40