×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

uplaod file to http server sing power shell
2

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.

RE: uplaod file to http server sing power shell

Uploading files with an HTTP form submitted by POST already needs a server-side script receiving the file, it arrives in a temp dir and needs to be copied to a destination location in that case. I'm quite sure the same applies to a PUT request, there is no default web server action just taking the file in and putting it where you specify it with the URL.

I'd go for FTP STOR, not HTTP PUT.

Bye, Olaf.

RE: uplaod file to http server sing power shell

(OP)
thanks for reply :) . I am very much new to this . So you are telling me that I should use HTTP STOR process for this? Any kind of pdf url,post regarding will be helpful .

RE: uplaod file to http server sing power shell

I agree with what Olaf has said.

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
If so, find out specifically if you are to send your file as FTP or SFTP
* A Web Service to receive HTTP PUT/POST transfers.
If so, find out specifically if it needs you to send your file as an HTTP PUT or HTTP POST
* or what?

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

(OP)
thanks for reply :) .. My web server is http .. and I want to just upload my local xml file to http server .... that's all. how can I achieve that using power shell.. creating web service using power shell which will upload files to http server..

RE: uplaod file to http server sing power shell

OK. So your remote server is providing you a Web Service using one of the HTTP protocols and not an FTP/SFTP site.

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

You need to change from HTTP to FTP, you need an FTP url, not HTTP. It's far easier to FTP a file than to upload it via HTTP.
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

A while back, I was given some advice on how to upload a file or files using FTP.

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 -->

WAIT "Uploading file, please wait...." WINDOW NOWAIT

cCrLf = CHR(13) + CHR(10)
* --- Build a String of what needs to be in the SEND.TXT file ---
* --- In this way VFP can fill in the appropriate values from the 'mjobupload' variables ---

mfileone="thenameofyourfile"
mfiletwo="anotherfileifyouhaveone"

cSendTextStr = "OPEN ftp.yoursite.com" + cCrLf ;
          + "ftpusernumber-X" + cCrLf ;
          + "password" + cCrLf ;
          + "binary"  + cCrLf ;
          + "send " + fileone + cCrLf ;
          + "send " + filetwo + cCrLf ;
          + "close"  + cCrLf ;
          + "bye"  + cCrLf ;
          + "exit"

* --- Now Write String Out to File (SEND.TXT) ---

STRTOFILE(cSendTextStr, "send.txt")

RUN ftp  -i -s:send.txt

WAIT "File uploaded...." WINDOW NOWAIT
RETURN 

Create a file called send.txt and include the below obviously changing the settings to your FTP

CODE -->

OPEN ftp.yoursite.com
ftpusernumber-X
password
binary
send fileone
send filetwo
close
bye
exit 

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close