$req = [System.Net.FtpWebRequest]::create('ftp://myserver' )
$req.Method = [System.Net.WebRequestMethods+Ftp]::ListDirectory
$req.Credentials = New-Object net.NetworkCredential ("USER" ,"PAss" )
$response = $req.GetResponse()
$stream = $response.GetResponseStream()
$reader = New-Object io.streamreader($stream)
$reader.ReadToEnd()
but I error out on upload or download.
$req = [System.Net.FtpWebRequest]::create('ftp://myserver' )
$req.Method = [System.Net.WebRequestMethods+Ftp]::UploadFile
$req.Credentials = New-Object net.NetworkCredential ("USER" ,"PAss" )
# $req.Binary = False <<errors hence commented out
$Put = $req.GetRequestStream
$Put.Write("C:\tlist") <<<<<<error here
# $Put.Write("C:\tlist")
Method invocation failed because [System.Management.Automation.PSMethod]
doesn't contain a method named 'Write'
At line:1 char:11
+ $Put.Write( <<<< "C:\tlist")
$Put.Close()
$response = $req.GetResponse()
$stream = $response.GetResponseStream()
$reader = New-Object io.streamreader($stream)
$reader.ReadToEnd()
shouldn't I be able to change listdirectory for any of these valuse?
# AppendFile -Represents the FTP APPE protocol method that is used to
append a file to an existing file on an FTP server.
# DeleteFile -Represents the FTP DELE protocol method that is used to
delete a file on an FTP server.
# DownloadFile -Represents the FTP RETR protocol method that is used to
download a file from an FTP server.
# GetDateTimestamp
# GetFileSize -Represents the FTP SIZE protocol method that is used to
retrieve the size of a file on an FTP server.
# ListDirectory -Represents the FTP NLIST protocol method that gets a
short listing of the files on an FTP server.
# ListDirectoryDetails -Represents the FTP LIST protocol method that
gets a detailed listing of the files on an FTP server.
# MakeDirectory -Represents the FTP MKD protocol method creates a
directory on an FTP server.
# PrintWorkingDirectory -Represents the FTP PWD protocol method that
prints the name of the current working directory.
# RemoveDirectory -Represents the FTP RMD protocol method that removes a
directory.
# Rename -Represents the FTP RENAME protocol method that renames a
directory.
# UploadFile -Represents the FTP STOR protocol method that uploads a
file to an FTP server.
# UploadFileWithUniqueName
I am obvivously a neewbe to .net and hopefully missing something simple.
any help would be greatly appreciated.
> $Put = $req.GetRequestStream
> $Put.Write("C:\tlist") <<<<<<error here
> # $Put.Write("C:\tlist")
GetRequestStream is a Method so you must write parenthesis:
$Put = $req.GetRequestStream()
hth
Max
Try using $false.
> $Put = $req.GetRequestStream
> $Put.Write("C:\tlist") <<<<<<error here
> # $Put.Write("C:\tlist")
The Stream Write method has this signature: Write(byte[] bytes, int offset,
int count). So try:
$put.Write(([text.encoding]::Unicode.GetBytes("C:\tlist")), 0, 0)
--
Keith
Example:
Static Method
[Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey()
http://msdn2.microsoft.com/en-us/library/microsoft.win32.registrykey.openremotebasekey.aspx
Static Field
[Microsoft.Win32.Registry]::LocalMachine
http://msdn2.microsoft.com/en-us/library/microsoft.win32.registry.localmachine.aspx
Enumeration:
[Microsoft.Win32.RegistryHive]::LocalMachine
http://msdn2.microsoft.com/en-us/microsoft.win32.registryhive.aspx
"Jim B" <jim....@gmail.com> wrote in message
news:1169091499.3...@m58g2000cwm.googlegroups.com...
function ftpfile{
param([string]$filename,[string]$port=21,[string]$user,[string]$pass,[string]$ftpUri)
$fileContent = [System.IO.File]::ReadAllBytes($fileName)
$req = [System.Net.FtpWebRequest]::create($ftpUri)
$req.Method = [System.Net.WebRequestMethods+Ftp]::UploadFile
$req.Credentials = New-Object System.net.NetworkCredential($user,$pass)
$req.UseBinary = $true
$req.ContentLength = $fileContent.Length
$requestStream = $req.GetRequestStream()
$requestStream.Write($fileContent,0, $fileContent.Length)
$requestStream.Close()
}
ftpfile -filename "C:\test.exe" -port 21 -user "uid" -pass "pwd"
-ftpUri "ftp://servername.domain/path/test.exe"
--
campi