uplaod file to http server sing power shell
uplaod file to http server sing power shell
(OP)
I want to transfer a XML file to http server (http://abcdef.com/somefolder/abcdef.xml) . I wrote scripts for this and it's running but actually it's not uplaoding the files to http server .
My code
$sourceFilePath = "C:\Temp\NEWFOLDER\ABCDEF.XML"
$siteAddress = "http://abcdef.net/inetpub/temp/XML/"
$urlDest = "{0}/{1}" -f ($siteAddress, "ABCDEF.XML");
$UserName = "XXXXX"
$Password = "XXXXX"
function uploadFile()
{
Param ([string] $sourceFilePath,
[string] $siteAddress ,
[string] $urlDest,
[string] $UserName,
[string] $Password)
$webClient = New-Object System.Net.WebClient;
$webClient.Credentials = New-Object System.Net.NetworkCredential($UserName,$Password);
("*** Uploading {0} file to {1} ***" -f ($sourceFilePath, $siteAddress) ) | write-host -ForegroundColor Green
$webClient.UploadFile($urlDest, "PUT", $sourceFilePath);
}
uploadFile $sourceFilePath $siteAddress $urlDest $UserName $Password
ERROR
Exception calling "UploadFile" with "3" argument(s): "The remote server returned an error: (503) Server Unavailable."At
C:\ABCDEF-documents\upload-file.ps1:40 char:13
+ $webClient.UploadFile($urlDest, "PUT", $sourceFilePath);
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : WebException
Can anyone help me on this . Any clue will be helpful.
My code
$sourceFilePath = "C:\Temp\NEWFOLDER\ABCDEF.XML"
$siteAddress = "http://abcdef.net/inetpub/temp/XML/"
$urlDest = "{0}/{1}" -f ($siteAddress, "ABCDEF.XML");
$UserName = "XXXXX"
$Password = "XXXXX"
function uploadFile()
{
Param ([string] $sourceFilePath,
[string] $siteAddress ,
[string] $urlDest,
[string] $UserName,
[string] $Password)
$webClient = New-Object System.Net.WebClient;
$webClient.Credentials = New-Object System.Net.NetworkCredential($UserName,$Password);
("*** Uploading {0} file to {1} ***" -f ($sourceFilePath, $siteAddress) ) | write-host -ForegroundColor Green
$webClient.UploadFile($urlDest, "PUT", $sourceFilePath);
}
uploadFile $sourceFilePath $siteAddress $urlDest $UserName $Password
ERROR
Exception calling "UploadFile" with "3" argument(s): "The remote server returned an error: (503) Server Unavailable."At
C:\ABCDEF-documents\upload-file.ps1:40 char:13
+ $webClient.UploadFile($urlDest, "PUT", $sourceFilePath);
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : WebException
Can anyone help me on this . Any clue will be helpful.
RE: uplaod file to http server sing power shell
I'd go for FTP STOR, not HTTP PUT.
Bye, Olaf.
RE: uplaod file to http server sing power shell
RE: uplaod file to http server sing power shell
NO you do not have to use an HTTP <Anything> to merely transfer a file from your site to another site.
In some cases you use an HTTP PUT/POST and in others you use FTP/SFTP - it all depends on what the receiving site is providing for your use.
It sounds like the first thing you need to do is to find out specifically what the remote site is offering you.
* An FTP/SFTP site
Then, once you know that and have received the appropriate credentials for it, you can then determine what you code needs to do.
Good Luck
JRB-Bldr
RE: uplaod file to http server sing power shell
RE: uplaod file to http server sing power shell
Now you need to find out if that Web Service is supporting HTTP PUT's or HTTP POST's because your code will need to differ somewhat depending on which it is.
And you will need to find the precise protocol syntax that the Web Service expects in order to handle the file transfer.
Things like Destination folder, etc. are either 'hard coded' into the Web Service's code or they are passed to it as one of the Parameters of the POST/PUT URL syntax.
Also, as I said above, if your Remote HTTP Web Service has special authentication credentials you need to get that information as well.
For example the last one I did was for sending XML files to a State Agency.
Their Web Service had its own handling of the Destination folder (it was NOT passed) and it required the password to be base64 encrypted.
Each Web Service may very likely have been created to have its own unique requirements.
NOTE: I have never used 'Power Shell' so I can't help you with that, but I have created a few VFP applications that run HTTP file transfer routines.
Good Luck
JRB-Bldr
RE: uplaod file to http server sing power shell
Your hosting will include FTP access and what you upload via FPT will be available via browser (HTTP).
Bye, Olaf.
RE: uplaod file to http server sing power shell
The thread for reference can be found here: thread184-1766403: Export records from main app, import to another app and return
I needed to run an automated process via an app and now use the following:
Create a file called sendftp.prg and add the following (replacing details with your own FTP)
CODE -->
Create a file called send.txt and include the below obviously changing the settings to your FTP
CODE -->
Needless to say, files are uploaded to a space on our server where they are stored for later use as downloads.
If this is what you're trying to achieve, then hope it assists.
Thank you
Steve Williams