Transfer File via HTTP POST?

Post any question you may have in regards to GoAnywhere Director and let our talented support staff and other users assist you.

Transfer File via HTTP POST?

Postby rkanemeier » Mon Nov 16, 2009 9:49 am

Has anyone used GoAnywhere Director to transfer a file using HTTP POST? I was able to successfully perform a GET using a sample project from Linoma. However, I am getting an invalid server message when I try to use a POST.

My URI is the location of the file i am trying to send off the AS/400 IFS. My response body destination is FILE and my response body file is the filepath of the destination of the file.

Any tips/suggestions would be appreciated.
rkanemeier
Verified User
 
Posts: 4
Joined: Mon Oct 05, 2009 3:39 pm

Re: Transfer File via HTTP POST?

Postby rkanemeier » Wed Nov 18, 2009 11:54 am

As a follow up, I am now able to upload a file using the POST "element". It does get a little tricky though trying to figure out what "element(s)" to use in your HTTP "task". Since my project has vendor sensitive information in it, I will post a "semi-step-by-step" guide on how to POST a file via HTTP. Please keep in mind that my knowledge on HTTP transfers is very limited and I'm only posting "what I know works". Feel free to add to this thread if you find my terminology or methodology is wrong.

1. Create a new project
2. Add the Create Workspace task (optional)
3. Add the HTTP task
4. In the HTTP task, click on the Advanced tab
5. For the HOST, specify the web address of the target system. For me this was actually an application! It looks something like http://mydomain/folder/login.asp. Specify the user and password if your server is "protected" with login credentials.
6. Within the HTTP task, add a POST element.
7. For the POST element, In the URI field, put the fully qualified path name of the target system program that will perform the actual upload. In my case it was something like http://mydomain/folder/upload.asp.
8. Still in the POST element, add a FILE element.
9. In the FILE element, type in the name of the HTTP variable from your "upload.asp" program that stores the file name to be uploaded. In my case, the filename on the upload.asp form was called "upfile".
10. In the FILE element, type the filename AND path of the source file you are trying to transfer. I am on an AS/400, and the file I was transferring was on the IFS. The filename and path I specified was /FOLDER1/File1.csv.

I am still having some minor issues with getting the file to be stored in a specific folder on the target system, however, I believe it has something to do with the upload.asp program. Anyway, fwiw.
rkanemeier
Verified User
 
Posts: 4
Joined: Mon Oct 05, 2009 3:39 pm

Re: Transfer File via HTTP POST?

Postby Support_Erick » Thu Nov 19, 2009 11:54 am

The step by step guide you posted above looks ok and should work, but I would like to make a couple adjustment.

When to use workspaces:
Omit step 2 as there is no need to have a workspace in this project example. A create workspace task is used to create a temporary file location within GoAnywhere to store files as they are being processed. Having the workspace gives you the ability to quickly clean up temporary files after other tasks has completed processing them. For example, if you were doing an HTTP download (instead of an upload), you could create a workspace to store the downloaded file in. Say the file you are downloading is a CSV file which we will store in the temporary workspace. After the download, you would have another task such as Read CSV to parse the downloaded file, followed by an SQL Task to insert the downloaded data into a database file/table. After all processing is completed, you could have a Delete Workspace Task to remove the temporary folder and clean up all working files.

HTTP Host attribute:
On step 5, the host name is simply the domain name or IP of the server you are connecting to. That field should contain nothing other than the 'mydomain' section of the URL. For example, if your URL you are posting to is http://www.linomasoftware.com/folder/upload.asp, the host name field would contain only www.linomasoftware.com. Having the full URL in this field could cause problems.

Using Resource:
Instead of specifying the host name and other connection information on the Advanced tab, you could create an HTTP Resource (Resources -> HTTP Servers -> Add HTTP Server) and store your connection information there. The resource could then be selected on the Basic tab of the HTTP Task. Defining a resource gives you the ability to use this same server connection information (host name, user, password, etc...) across multiple projects and HTTP tasks without having to specify the connection information in the advanced tab each time. If you are simply setting up one project and will not use this HTTP server anywhere else, then specifying the information on the advanced tab is fine.

Post URI attribute:
In step number 7, the URI is the path to the target file or application on the server you are connecting to. So the URI field should only contain the path information after the domain name. So in the example http://www.linomasoftware.com/folder/upload.asp, the URI would be /folder/upload.asp

NOTE: What your project seems to be doing is making a connection to /login.asp with the provided credentials. Then when the POST method is executed, it is establishing a whole new connection to the server to /upload.asp. It is most likely re-authenticating when accessing upload.asp. By following the updated steps I posted below, you should be able to accomplish the same outcome with a single connection to the server.

I have updated your steps a bit and posted them below. I hope this explains/clears up a couple things about the HTTP task.

  • Create a new project
  • Add the HTTP task
  • In the HTTP task, click on the Advanced tab
  • For the HOST, specify the domain name of the target system. This should be either the domain name or IP address of the system. For example, 192.168.1.1 or http://www.linomasoftware.com. If the target web server requires authentication, specify the username and password.
  • Within the HTTP task, add a POST element.
  • For the POST element, In the URI field, put path on the server to the web application that will process the upload. This value is the rest of the URL after the domain name. In the case of the URL http://mydomain/folder/upload.asp, use the URI /folder/upload.asp
  • Still in the POST element, add a FILE element.
  • In the FILE element, type the path AND filename of the source file you are trying to transfer. The file must be locate on or accessible from the system where GoAnywhere is installed. For example, if GoAnywhere is running on an AS/400 and your file is on the IFS, specify a path similar to /FOLDER1/File1.csv
Support_Erick
Support Specialist
 
Posts: 11
Joined: Thu Mar 05, 2009 10:20 am

Re: Transfer File via HTTP POST?

Postby rkanemeier » Thu Nov 19, 2009 5:29 pm

Erick,

Thanks a ton for your response! I have some questions though, if that's ok.

Workspaces:
It sounds like you don't recommend creating them unless the project has multiple tasks that uses temporary files created by TASKS like WRITE CSV etc. Is this a correct assessment?

HTTP Host attribute:
I changed this and it worked as you suggested

Resources:
I am actually trying to develop a dynamic project that will be executed for all similar HTTP POSTS (we have a few). I see the advantage of using the resource and we do use them for some projects.

POST URI Attribute:
I changed this per your recommendation and it worked like a charm as well.


Now the only trouble I'm having is getting the file to POST to the correct folder on the target system (a Windows server). It seems I have to do some researching on what our upload.asp program is doing with the file so that I can tell it to put it in a specific spot. I did find a variable in the upload.asp file called filepath but I don't know how to assign a variable on a POST element in GoAnywhere. Well, I should say I "tried" assigning a request parameter to the POST element in the GoAnywhere project but that did not seem to help. Any suggestions?
rkanemeier
Verified User
 
Posts: 4
Joined: Mon Oct 05, 2009 3:39 pm

Re: Transfer File via HTTP POST?

Postby Support_Ron » Fri Nov 20, 2009 9:43 am

It should be possible for you to dictate the folder that the file is uploaded to.
The upload.asp program would most likely have some sort of parameter (in addition to the file) that it is expecting that he could post along with the file to tell it what directory to put the file in.
Support_Ron
Support Specialist
 
Posts: 11
Joined: Tue Mar 03, 2009 5:45 pm

Re: Transfer File via HTTP POST?

Postby rkanemeier » Fri Nov 20, 2009 11:12 am

Ron,

I looked at the .asp page and it is stripping out all characters from the input path (ie. C:/folder1/file1.txt) to get to the filename (in this case it would be file1.txt). THEN it uses Session("UserId") and uses that value as part of the path. Therein lies my problem. I'm not sure how to get the target server to remember who the UserId is. This could be a .asp thing. Let me show some of the.asp code to clarify my boggle:

Code: Select all
filepathname = UploadRequest.Item("blob").Item("FileName")
User =Session("UserID")
filename =   Right(filepathname,Len(filepathname)-InstrRev(filepathname,"\"))
value = UploadRequest.Item("blob").Item("Value")
FileLocation = ("C:\folder1\folder2\" & User)
Set MyFile = ScriptObject.CreateTextFile(FileLocation &"\"& filename)


As you can see the FileLocation is derived using User as part of the path. User comes from Session("UserId"). I "assumed" that the Session() method/function taps into a system value. Why wouldn't this system value be retained after the GoAnywhere project provides login credentials?

Oh, something of importance to note: I'm not the .asp programmer at our company lol.
rkanemeier
Verified User
 
Posts: 4
Joined: Mon Oct 05, 2009 3:39 pm

Re: Transfer File via HTTP POST?

Postby dmcintyre » Fri May 07, 2010 2:03 pm

I have a similar need, which is to post an XML to a site via HTTPS. The XML I will be sending will contain employee records to be either added or updated to a remote database. Though, in my case, I also need to receive an XML file as a response to my post. This XML will contain the result status of my post.

Using the steps to send the Post, what will be needed to retrieve the XML file from the response?

Thank you,
Don
dmcintyre
 
Posts: 1
Joined: Thu May 06, 2010 4:34 pm

Re: Transfer File via HTTP POST?

Postby Support_Duane » Thu May 20, 2010 10:58 am

Select the “file” option in the Response Body Destination field, provide a path and file name in the Response Body File field, and select the appropriate option in the When Response Body File Exists field -
the default for which is "rename". If you leave the default, or select "rename", be sure to make an entry in the Response Body File Variable field so that you can use that variable in subsequent tasks.
Support_Duane
Support Specialist
 
Posts: 65
Joined: Thu Mar 05, 2009 3:49 pm


Return to Community Forum

Who is online

Users browsing this forum: mattolsen and 1 guest