Highlighted

InDesign CS6 Socket FTP connection

New Here ,
Apr 29, 2020

Copy link to clipboard

Copied

In my scripts I need to upload generated images by InDesign (CS6) to FTP server. To connect to FTP I'm using Sockets. However I stumble on a problem. Whenever I try to make connection to that server it does connect but for any of commands (e.g. USER) send through the sockets once the initial connection is made the response is just empty string for minutes if not hours (I stopped waiting after few minutes since it's already way to long to wait). 

 

The weird thing in this is that when I'm checking same credentials in apps like FileZilla all works fine - connection is made, server responding. Also if I use same code to connect to another server (only changes are in server name and credentials) it also works fine.

 

What could be the reason for such behavior? I'll add that the server that I'm trying to connect is within netcup.net subdomains.

TOPICS
Scripting

Views

143

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

InDesign CS6 Socket FTP connection

New Here ,
Apr 29, 2020

Copy link to clipboard

Copied

In my scripts I need to upload generated images by InDesign (CS6) to FTP server. To connect to FTP I'm using Sockets. However I stumble on a problem. Whenever I try to make connection to that server it does connect but for any of commands (e.g. USER) send through the sockets once the initial connection is made the response is just empty string for minutes if not hours (I stopped waiting after few minutes since it's already way to long to wait). 

 

The weird thing in this is that when I'm checking same credentials in apps like FileZilla all works fine - connection is made, server responding. Also if I use same code to connect to another server (only changes are in server name and credentials) it also works fine.

 

What could be the reason for such behavior? I'll add that the server that I'm trying to connect is within netcup.net subdomains.

TOPICS
Scripting

Views

144

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Apr 29, 2020 0
Explorer ,
Apr 29, 2020

Copy link to clipboard

Copied

Can you show us the code you are using and is it ExtendScript you are using?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 29, 2020 0
Irhak LATEST
New Here ,
May 04, 2020

Copy link to clipboard

Copied

I cannot publish login credentials to that server (it's client's server). I know though that those are correct - as I said I can log in with them with FileZilla but can't from InDesign. If I try connect to different server I can log both from FileZilla and scripts.

And as editor I'm using ExtendScript Toolkit.

The only difference I know between those 2 servers is that client's one got ssl installed on it.

 

Below is the core of the code that I'm currently using for just initial connection (without pushing files to the server):

var ftp = {

	verbose:true,
	encoding:"BINARY", // or ASCII

	log:function(message)
	{
		if(this.verbose)
		console.log(message);
	},

	error:function(message) {

		console.log("ERROR:"+message);
	},

	connect:function(host, port, user, pass) {

       
        this.channel = new Socket();     
        this.channel.encoding = "UTF-8";
  

		if (this.channel.open(host + ":" + parseInt(port)))
		{
			try {
				// get welcome message
				if (!this.response(220))
				error.log( "FTP connection refused." );

              //  console.log(this.channel.read());
              
                 this.command("USER " + user);
				if (!this.response(230, 332))
				error.log( "Server rejected username." );


				this.command("PASS " + pass);
				if (!this.response(202, 230))
				error.log("Server rejected username or password." );

			}
			catch (e) {
				this.close();

			}
			finally {
				this.log( "FTP Connected!" );
				return true;
			}
		}
		else
		{
			this.error('Internet connection?');
		}

	},

	command:function(cmdS) {
		if (cmdS)
		{
			this.log("[CMD]:"+cmdS);
			return this.channel.write(cmdS + "\r\n");
		}
		else
		{
			return this.channel.write("\r\n");
		}
	},

	response:function(expectLow, expectHigh) {
		var replyS;
		var code;

		// bypass any marks (and empty lines)
		do {
         
			replyS = this.channel.read();
            console.log(replyS);

			code = replyS.match(/^(\d{3})\s/m);
		}
		while (!code);

		this.log("[RSP]:"+replyS);

		// this should be the actual response
//		code = replyS.match(/^(\d{3})\s/m);
		if (code && code.length == 2) {

			code = parseInt(code[1]);
			if (code == expectLow || (expectHigh && code > expectLow && code <= expectHigh)) {
//				if (_FTPC_DO_LOG) logFile.writeln("--Found code: " + code);
				return replyS;
			}
		}

		return null;
	},
	close:function () {
		// send quit
		this.command("QUIT");
		this.response(221);
		// close controlChannel
		this.channel.close();
	}
}

Code above is included withing 'main' script as lib/ftp.js:

#targetengine "session";
#include "lib/ftp.js";
#include "lib/console.js";
#include "app/global_vars.js";
alert("connecting");
connection=ftp.connect(<host>, 21, <login>, <pass>);
alert("connected");

 conosle.js and global_vars.js are just for printing results in nice window.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
May 04, 2020 0