Client-Server implementation for uploading a file using Socket - client-server

I want to implement a Client-Server program in which the client has to send a file to the server. In this case, what is the efficient way to send the file to server?
I am thinking in the following method,
After the connection establishment, First, I have to send the file name (which i want to upload) to server from client. Then I have to send the file content to server. The server will wait for the file content after received the file name from client.
So, for uploading a file, I need 2 write method in client & 2 read method in server.
Is this ok? Is there any other efficient way for doing this?

I think that your idea is correct. Maybe you should consider not to send files name (only the extension line .jpg) and let server generate one. This will prevent overwriting some already existing files.

Related

how to upload three json files in oneshot with spring integration?

I want to upload three json file from my local directory to a remote SFTP location in one shot. I cannot afford to upload them one by one. What inbound adaptor, channel and sftpoutbound gateway configuration should I use ? I know there is something call mput in outbound gateway. But I have never used the mput code wise.
See docs for MPUT command: https://docs.spring.io/spring-integration/docs/current/reference/html/sftp.html#using-the-mput-command
The message payload must be a java.io.File (or String) that represents a local directory.
So, a request message for MPUT command must have a payload as a local dir with files you'd like to transfer. Therefore it might not be ideal for you to deal with a file inbound channel adapter.
You can aggregate polled files into a single directory before sending a message with it into that SFTP outbound gateway.

How to send a download request to a server without downloading the file?

I want to send a request to a server to download a file. However, when the file is sent by the server, I don't want to actually receive the file. I'm trying to see if it's possible for me to overload a server's bandwidth without having to actually download files.
I'm guessing this should be possible using some sort of a UDP protocol where no acknowledgements are required.
If the download is available via HTTP GET, you can try sending an HTTP HEAD request with the same headers to try to receive a response without the server actually sending the file.

Thrift - send files from server to client

I am using thrift and I have a java client and server. I am calling some functions on the server from the client and that part is already working. After calling the functions, I have an output file created in the machine where the server is running. I need to return this file to the client. How can I accomplish this? Should I use TFileTransfer? If not, is there a better way to get the data back?
In a sense, I need to create a client within the server..
I am new to Thrift and any help will be appreciated.

is ftp data connection is only for one file?

I have a client trying to upload multiple files to FTP server in passive mode.
The client sends PASV command and the server responds with the relevant ip and port.
Is it possible to send multiple files on this one data connection? or the client need to send the PASV command and get a new port for each file?
Since the only indicator of the end of file is the close of the connection and because you cannot transfer any more data after the connection has closed, you will not be able to transfer more than one file using the same data connection.
But, maybe you tried to ask a different question, that is if is possible to have multiple data transfers (and thus multiple data connections) after a single PASV command? I can see nothing in RFC959 which directly would prevent this and reusing the same target port on the server. And because access would be done from different source ports on the client this should also not give problems with TCP connection states. But, in practice you will probably see problems because if you try to use this from the client side, because lots of servers create the listener only for a single data connection. So you better precede each data transfer with a new PASV command, like existing clients do.

Server to server transfer using AJAX

This questions was asked during one of the interview. How to transfer data from one server to another using AJAX? Is it really possible?
AJAX is generally used on the client side, not usually the server side.
It sends requests to a server.
You probably need to provide more information about what you are trying to achieve to get a decent answer.
If you are wanting to transfer data from a "client" to a server then you could send the data in a variety of ways - especially with AJAX. Just how depends on what data type and size. Requests from a client to server (HTTP) can include POST data, which can carry your data to the server.
If you are using AJAX on a client and wanting to use it to transfer data from one remote server to another then you could get AJAX on your client to call a script on the server that would instigate the transfer from the server to another server in some way. (such as FTP or SCP maybe - or even using a server to server HTTP POST)
If you can be a little more specific about what you need to do then I will try and give you a better answer.

Resources