Create File and Write File

Hi All,

I’m trying to create a file on the server. And then transfer it via ftp. The first part of the code is:

var _server_file = plugins.file.createFile("myimage.jpg");
		_success = plugins.file.writeFile(_server_file, _files[0].getBytes());

Where _files[0] is the array containing the array of images (files);

My issue is, at the time of completion i see the status as “loading” and then “server error”. The file gets transferred to the ftp location. However it is corrupted.

Any ideas?

Regards,
Hareendra

Hi Hareendra,

Without seeing any of the real code it’s hard to say what’s going on.
But do you see any errors in the Servoy log ?

Hi,

A couple of things clarified: There are no errors in the server log. I found out that the image gets successfully saved to the server location (it is NOT corrupt)
So the corruption must occure during the FTP transfer.
I am using a ftp plugin that I developed. It seems to transfer txt file successfully though. The code is as follows:

var _success = true;
	
	var _file_extension = _files[0].getName().split('.')[1];
	//get FTP details
	var _fs_ftp_logins = globals.getFTPDetails('DOWNLOAD_FILES');	
	
	if(_fs_ftp_logins != null) {
		var _local_upload_path =  _fs_ftp_logins.local_folder_path + 'work/';		

		var _server_file = plugins.file.createFile(_local_upload_path + _file_save_name + "." + _file_extension);
		_success = plugins.file.writeFile(_server_file, _files[0].getBytes());
		
		application.output(_server_file);
		
	}
	else {
		_success = false;
		application.output('Could not load Master-Data: FTP Logins');
	}
	
	//upload file to FTP location
	if(_success) {
		//upload file to FTP location build folder
		_success = plugins.rp_ftp_plugin.sendFile(_fs_ftp_logins.ftp_host_name, _fs_ftp_logins.ftp_user_name, _fs_ftp_logins.ftp_password, _file_save_name+ '.' + _file_extension, _file_save_name+ '.' + _file_extension, _fs_ftp_logins.ftp_folder_path + 'build/', _local_upload_path);
		
		//move file to work folder
		if(_success) {
			_success = plugins.rp_ftp_plugin.renameFile(_fs_ftp_logins.ftp_host_name, _fs_ftp_logins.ftp_user_name, _fs_ftp_logins.ftp_password, _fs_ftp_logins.ftp_folder_path + 'build/' + _file_save_name + '.' + _file_extension, _fs_ftp_logins.ftp_folder_path + 'work/' + _file_save_name + '.' + _file_extension);
			
			if(_success) {
				plugins.file.moveFile(_local_upload_path + _file_save_name + '.' + _file_extension, _fs_ftp_logins.local_folder_path + 'proc/' + _file_save_name + '.' + _file_extension);
			}
			else {
				_success = false;
				application.output('Could not move file in FTP location');
			}
		}
		else {
			_success = false;
			application.output('Could not upload file to FTP location');
		}
	}
	
	return _success;

Regards,
Hareendra

Hi,

I just found out that it was an issue with the FTP plugin.
Then I switched to the IT2B plugin. Now it works! By the way do you have any idea why the put() method does not return a value?

Regards,
Hareendra

Hi Hareendra,

hareendra:
By the way do you have any idea why the put() method does not return a value?

Good question, also Get() doesn’t return a boolean to signify a successful transfer or not.
I don’t know the answer to this, I suggest you ask Marcel (the author).