Was wondering if someone could help me out here...in the past, we automated a ftp process to one of our customers, using a batch file and the ftpcmd.dat command. Now, they have switched to a https site, and as a result, broke our current process.
Doing some searching, I was able to find links using PowerShell as an alternative, particularly, the Invoke-WebRequest cmdlet. Going step-by-step, I was able to connect to the site; here's what I did:
# The first command uses the **Invoke-WebRequest** cmdlet to send a sign-in request. The command specifies a value of "FB" for the value of the *SessionVariable* parameter, and saves the result in the $R variable.When the command completes, the $R variable contains an **HtmlWebResponseObject** and the $FB variable contains a **WebRequestSession** object.
$R=Invoke-WebRequest https://website -SessionVariable fb
# The second command shows the **WebRequestSession** object in the $FB variable.
# The third command gets the first form in the **Forms** property of the HTTP response object in the $R variable, and saves it in the $Form variable.
$Form = $R.Forms
# The fourth command pipes the properties of the form in the $Form variable into a list by using the Format-List cmdlet.
$Form | Format-List
# The fifth command displays the keys and values in the hash table (dictionary) object in the Fields property of the form.
# The sixth and seventh commands populate the values of the email and pass keys of the hash table in the **Fields** property of the form. You can replace the email and password with values that you want to use.
# The eighth command uses the **Invoke-WebRequest** cmdlet to sign into the Facebook web service.The value of the *Uri* parameter is the value of the **Action** property of the form. The **WebRequestSession** object in the $FB variable (the session variable specified in the first command) is now the value of the *WebSession* parameter. The value of the *Body* parameter is the hash table in the Fields property of the form and the value of the *Method* parameter is POST. The command saves the output in the $R variable.
$R=Invoke-WebRequest -Uri ("https://website" + $Form.Action) -WebSession $FB -Method POST -Body $Form.Fields
# When the command finishes, the **StatusDescription** property of the web response object in the $R variable indicates that the user is signed in successfully.
Using this, I was able to sign in...trying to upload the file, this is where I got errors...I tried creating a variable, which would store the path of the file:
$picPath = "D:\File path\Document.csv"
# Then I tried to use the Invoke-WebRequest cmdlet, but got an error: Unauthorized
$R=Invoke-WebRequest -Uri ("https://website" + $Form.Action) -Method Put -Infile $picPath
# I used the $Form | Format-List and saw the Method was Post, so I changed it to Post and got a different error: The selected resource was not found
$R=Invoke-WebRequest -Uri ("https://website" + $Form.Action) -Method Post -Infile $picPath
I also embedded the field names on the 2nd form, once I signed in successfully...
Just wondering if I'm on the right path...please let me know if you need additional info/details...