2010-02-25 13 views
5

में लॉग इन नहीं है मैं काम करने के लिए PowerShell स्क्रिप्ट प्राप्त करने के लिए संघर्ष कर रहा हूं। मैं पावरशेल के लिए बहुत नया हूं इसलिए कुछ बेवकूफ हो सकता है।पावरहेल ftp अपलोड त्रुटि 530

$sourceuri = "ftp://ftp.example.com/myfolder/myfile.xml" 
$username = "user" 
$password = "password" 

# Create a FTPWebRequest object to handle the connection to the ftp server 
$ftprequest = [System.Net.FtpWebRequest]::create($sourceuri) 

$credentials = New-Object System.Net.NetworkCredential($username,$password) 
# set the request's network credentials for an authenticated connection 
$ftprequest.Credentials = $credentials 

$ftprequest.Method = [System.Net.WebRequestMethods+Ftp]::UploadFile 
$ftprequest.UseBinary = 1 
$ftprequest.KeepAlive = 0 

# read in the file to upload as a byte array 
$content = gc -en byte $fileName 
$ftprequest.ContentLength = $content.Length 
# get the request stream, and write the bytes into it 
$rs = $ftprequest.GetRequestStream() 
$rs.Write($content, 0, $content.Length) 
# be sure to clean up after ourselves 
$rs.Close() 
$rs.Dispose() 

मैं निम्नलिखित त्रुटि मिलती है:

Exception calling "GetRequestStream" with "0" argument(s): "The remote server returned an error: (530) Not logged in." 
At C:\temp\copyfile.ps1:63 char:35 
+ $rs = $ftprequest.GetRequestStream(<<<<) 

मैं आसानी से इसे करने के लिए IE के माध्यम से कनेक्ट कर सकते हैं ताकि शायद सोचा कुछ और गलत था इतनी जल्दी सी # में ऐसा किया:

 string filePath = @"C:\temp\myfile.xml"; 
     string FTPAddress = @"ftp://ftp.example.com/myfolder"; 
     FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(FTPAddress + "/" + Path.GetFileName(filePath)); 
     request.Method = WebRequestMethods.Ftp.UploadFile; 
     string username = "user"; 
     string password = "password"; 
     request.Credentials = new NetworkCredential(username, password); 
     request.UsePassive = true; 
     request.UseBinary = true; 
     request.KeepAlive = false; 

     FileInfo file = new FileInfo(filePath); 
     request.ContentLength = file.Length; 
     int buffLength = 2048; 
     byte[] buff = new byte[buffLength]; 
     int contentLen; 

     FileStream fs = file.OpenRead(); 

     Stream strm = request.GetRequestStream(); 
     contentLen = fs.Read(buff, 0, buffLength); 
     while(contentLen !=0) 
     { 
      strm.Write(buff, 0, contentLen); 
      contentLen = fs.Read(buff, 0, buffLength); 
     } 

     strm.Close(); 
     fs.Close(); 

सी # पूरी तरह से काम करता है, सुनिश्चित नहीं है कि यह क्यों काम नहीं कर रहा है और उम्मीद है कि कोई मेरी त्रुटि को इंगित करने में सक्षम हो सकता है

संपादित करें

हल किया गया, नया यह कुछ बेवकूफ होगा। पासवर्ड में "$" चिह्न था, यह दोहरे उद्धरणों के भीतर था, लेकिन मुझे नहीं पता था कि इसे बचने की आवश्यकता होगी, बस इसके बारे में नहीं सोचा था। विडंबना यह है कि मुझे पासवर्ड इत्यादि बदलना पड़ा ताकि पोस्ट करना सुरक्षित हो।

+1

मैं कुछ भी नहीं देख सकता। केवल अंतर यह है कि आप सी # समाधान में 'UsePassive' का उपयोग करते हैं। त्रुटियों से बचने के लिए आप अनियमित चर (= typos) से बचने के लिए 'Set-StrictMode -version ...' का उपयोग कर सकते हैं, लेकिन इस मामले में मुझे लगता है कि यह कुछ भी नया नहीं लाएगा। – stej

+0

हाय स्टीज, प्रतिक्रिया के लिए धन्यवाद। मुझे खुशी है कि यह सिर्फ मुझे नहीं, मैंने पावरशेल में सी # को दोहराने की कोशिश की। – Jon

+0

कई त्रुटियां डबल कोट्स के साथ 'समस्या $' का कारण बनती हैं :) – stej

उत्तर

2

मूल पोस्टर Jon से:

यह हल, नई यह कुछ बेवकूफ होगा। पासवर्ड में "$" चिह्न था, यह दोहरे उद्धरणों के भीतर था, लेकिन मुझे नहीं पता था कि इसे बचने की आवश्यकता होगी, बस इसके बारे में नहीं सोचा था। विडंबना यह है कि मुझे पासवर्ड इत्यादि बदलना पड़ा ताकि पोस्ट करना सुरक्षित हो।

0

उपयोगकर्ता नाम या पासवर्ड से केवल दोहरे उद्धरण को हटाएं क्योंकि कभी-कभी $ साइन समस्या का कारण बनती है। हर बार सिंगल कोट का उपयोग करना अच्छा होता है।

संबंधित मुद्दे