Akdora’s Blog

Programming, Oracle, Life, Fun

How to SFTP & FTP with Ant Tasks February 14, 2013

I will explain, how you can send files using ANT scipt over SFTP protocol.

Until i find how to use sftp protocol, I googled also ftp protocol. I will explaint it firstly,

If you want to use FTP protocol, you may use <ftp> tag of commons-net-1.4.1.jar. To do this :

  • Download commons-net-1.4.1.zip jar from here.
  • Add this jar to your ant lib folder using explorer or Define it from eclipse, “Window > Preferences > Ant > Runtime > Global Entries > Add Jar “
  • If you do not add this jar, you will get “Could not create type ftp due to java.lang.NoClassDefFoundError: org/apache/commons/net/ftp/FTPClientConfig” error.
  • Then write your ftp command to ant script
<target name="deploy" description="War is deploying">
 <ftp server="${ftp.host}" port="${ftp.port}" remotedir="${ftp.remotedir}" userid="${ftp.userid}" password="${ftp.password}" depends="yes">
      <fileset dir="${maven.build.dir}/war/" />
 </ftp>
</target>
  • If you use this method for SFTP (Port:22), You will get “error during FTP transfer: org.apache.commons.net.MalformedServerReplyException:
    Could not parse response code. Server Reply: SSH-1.99-OpenSSH_3.9p1” error.
  •  So, this method is valid for only FTP protocol.

 

After the experience below, I keep searching and find SCP task (min Ant 1.6).

  • Download jsch.jar0.1.42 or later from here
  • You may see examples in the page. This task can used to transfer any data from remote and local machine.
  • Add this jar to your ant lib folder using explorer or Define it from eclipse, “Window > Preferences > Ant > Runtime > Global Entries > Add Jar “
  • Then write your scp command to ant script
<target name="deploy" description="War is deploying">
    <scp file="${war.filepath}" sftp="true" trust="true" todir="userid:password@host:/to/dir/" />
</target>
  • If you do not add trust=”true” property, you will get “com.jcraft.jsch.JSchException: reject HostKey” error.

 

Good coding

Advertisement
 

Making Eclipse IDE Supports JSF 2.0 October 22, 2012

Filed under: Java,JSF — Akdora @ 8:29 am

Autocomplete was not working for JSF tags in my Eclipse. I googled it and finally found the solution on http://www.mkyong.com/jsf2/how-to-make-eclipse-ide-supports-jsf-2-0/

Thanx Mkyong.

The different thing I did is; I downloaded javax.faces-2.xx.xx.jar and saved in a specific folder. Then I created a user library with this jar. I did not use “jsf-api-xxx.jar and jsf-impl-xxx.jar“.

 

Solution Your profile could not be opened correctly in Chrome November 3, 2011

Hi,
When you try to open your chrome web explorer, if you get “Your profile could not be opened correctly” error, try to following solution:
There are several solutions on the web for this, but this is the easiest way:

-Close Chrome
-Go to “C:\Users\[user]\AppData\Local\Google\Chrome\User Data”
-Delete “Web Data” and “Web Data-journal” files. (If you cannot delete it, restart computer)
-Open Chrome

 

Clear extJS combo value when text is cleared or doesn’t match October 11, 2011

Filed under: Non-technical — Akdora @ 12:58 pm
Tags: , , , , ,

Here is the scenario;
-Type something to combobox
-Select something on the list
-Search and fill gridPanel
-Clear combobox and then search again
-It fills gridPanel with value that before we cleared.
I this this is a bug.
If you use Ext.getCmp(‘myCombo’).getValue() or Ext.getCmp(‘myCombo’).lastSelectionText, it does not work.
You have to use Ext.getCmp(‘myCombo’).getRawValue(). This works 😉
By the way comboBox is not readonly.

 

Java Debug Problem “Source not found.” May 23, 2011

Filed under: Java — Akdora @ 6:10 am

Quick Hint:
When you try to debug java code in eclipse, if you get “Source not found.” error with red letters. Here is the solution:
Down Arrow Icon Next to Debug Icon > Debug Configurations > Classpath Tab > Add Projects to User Entries
Add your project that cannot debug to this location.

 

HTML Image Saving Protection (Save Image As >> Point.gif) April 15, 2011

Filed under: CSS — Akdora @ 11:04 am
Tags: ,

If you have a web page with full of your copyrighted photos and do not want to visitors to save images in (easy way!) to their local computers. Let me show a trick about it.

In the photo (img) section of the page, we have always something like as following;

     <img id="myImg"
      src="http://www.google.com.tr/logoyapsana/images/templates/google_logo_01.gif"
      width="667" height="472"
      style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px;">
      </img>

On the image, when we right-click to the mouse and click to “Save Image As” command, we can save the image to our local disk. However, if we create a basic css style with a div below of the image, we can prevent this.

The important thing is in here: blank/point image’s dimensions has to be same with original image dimensions and css class of the component should include the following properties.

.BlankPixel { 
     position: absolute; 
     top: 0;
     left: 0; 
}
<div id="Photo">					
      <img id="myImg"
      src="http://www.google.com.tr/logoyapsana/images/templates/google_logo_01.gif"
      width="667" height="472"
      style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px;">
      </img> 
	</div>
       <div class="BlankPixel"><a href="#"><img src="https://akdora.files.wordpress.com/2011/04/point.gif" width="667" height="472"></a></div>

That’s it. This trick is an only basic measure for basic internet users. If someone want to save the photo, since the resource is downloaded to your computer to show up on the screen. It can be saved in any way.

Here is the full html example:
Copy the code and create a html page called “a.html” and open it. Try to save Google logo and see what happens 🙂 A file dialog box will ask you a location to save “https://akdora.files.wordpress.com/2011/04/point.gif&#8221; file! Not Google Logo!

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>My Title</title>
    <style type="text/css">
	.BlankPixel { 
		position: absolute; 
		top: 0;
		left: 0; 
	}
	</style>
  </head>
  <body>
    <div id="Photo" class="Photo">					
      <img id="myImg"
      src="http://www.google.com.tr/logoyapsana/images/templates/google_logo_01.gif"
      width="667" height="472"
      style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px;">
      </img> 
	</div>
	<div class="BlankPixel"><a href="#"><img src="https://akdora.files.wordpress.com/2011/04/point.gif" width="667" height="472"></a></div>
  </body>
</html>

 

C#.Net Download and Merge Images into One Bitmap Image April 5, 2011

Filed under: Visual C#.NET — Akdora @ 7:10 pm
Tags: , , ,

Recently, I developed a program that reads imdb.com web page for a specific movie and downloads movie info and images. Then, it merges the thumbnails images into one image file.

Firstly, I write the main code, that downloads the image files and merges them and save the merged image to system.

Note 1: In the code, arr variable is an ArrayList holds the picture urls.

Note 2: Image class is in “System.Drawing”


                                        Image[] images = new Image[arr.Length];
                                        for (int k = 0; k < arr.Length; k++){
                                             images[k] = Utils.DownloadImage(arr[k]);
                                        }
                                        Image mergedImage = Utils.MergeImages(images);
                                        if (mergedImage != null)
                                        {
                                             mergedImage.Save(fileFolder + "\\" + movieTitle + " Thumbnails.jpg");
                                        }

Here is inside of DownloadImage function:

        /// <summary>
        /// Function to download Image from website
        /// </summary>
        /// <param name="_URL">URL address to download image</param>
        /// <returns>Image</returns>
        public static Image DownloadImage(string _URL)
        {
            Image _tmpImage = null;

            try
            {
                // Open a connection
                System.Net.HttpWebRequest _HttpWebRequest = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(_URL);

                _HttpWebRequest.AllowWriteStreamBuffering = true;

                // set timeout for 20 seconds (Optional)
                _HttpWebRequest.Timeout = 20000;

                // Request response:
                System.Net.WebResponse _WebResponse = _HttpWebRequest.GetResponse();

                // Open data stream:
                System.IO.Stream _WebStream = _WebResponse.GetResponseStream();

                // convert webstream to image
                _tmpImage = Image.FromStream(_WebStream);

                // Cleanup
                _WebResponse.Close();
            }
            catch (Exception _Exception)
            {
                // Error
                Console.WriteLine("Exception caught in process: {0}", _Exception.ToString());
                return null;
            }

            return _tmpImage;
        }

Here is inside of MergeImages function:

        /// <summary>
        /// Merges Images into 1 Image.
        /// </summary>
        /// <param name="images">The Images you want merge</param>
        /// <returns>An Image of all images</returns>
        public static Image MergeImages(Image[] images)
        {
            if (images == null || images.Length <= 0)
            {
                return null;
            }
            Int32 imageWSize = 0;
            Int32 imageHSize = 0;

            for(int i=0;i<images.Length;i++)
            {
                if (images[i].Width > imageWSize)
                    imageWSize = images[i].Width;

                if (images[i].Height > imageHSize)
                    imageHSize = images[i].Height;
            }

            Int32 width = 0;
            Int32 height = 0;
            int picsInOneLine = 10;

            if (images.Length >= picsInOneLine)
            {
                width = picsInOneLine * imageWSize;
                decimal d = (images.Length + picsInOneLine) / picsInOneLine;
                height = (int)Math.Round(d) * imageHSize;
            }else{
                width = images.Length * imageWSize;
                height = imageHSize;
            }

            Bitmap bitmap = new Bitmap(width, height);
            int hhh = -1;
            int www = 0;
            for(int i=0; i<images.Length; i++)
            {
                Bitmap image = new Bitmap(images[i]);
                if (i % picsInOneLine == 0)
                {
                    hhh++;
                    www = 0;
                }

                //Get All of the x Pixels
                for (int w = 0; w < imageWSize; w++)
                {
                    //Get All of the Y Pixels
                    for (int h = 0; h < imageHSize; h++)
                    {
                        //Set the Cooresponding Pixel
                        int ww = w + (www * imageWSize);
                        int hh = h + (hhh * imageHSize);
                        bitmap.SetPixel(ww, hh, image.GetPixel(w, h));
                    }
                }
                www++;

            }
            //Return the new Bitmap
            return bitmap;
        }
 

PL/SQL Developer User Preferences (Windows 7) March 30, 2011

Filed under: Non-technical — Akdora @ 6:56 am

If you changed your computer and want “your PL/SQL developer login history and preferences” as well in your new computer. Copy the following folder to your new computer in the same path format!

C:\Users\[username]\AppData\Roaming\PLSQL Developer

If you need only the login history, open the following file:

C:\Users\[username]\AppData\Roaming\PLSQL Developer\Preferences\[username]\user.prefs

In the file, copy [LogonHistory] part to your new user.prefs file. It’s encrypted but it does not matter. PL/SQL Developer will dencrypt it 🙂

I need this, because I deal with a lots of database with a lots of schema.. It is really hard to remember the passwords sometimes, so i let the PL/Developer to remember them 🙂 (Preferences > Login History > Store with Password)

 

 

ORA-14047: ALTER TABLE|INDEX RENAME may not be combined with other operations March 21, 2011

Filed under: Oracle,SQL — Akdora @ 9:40 am
Tags: , , , , ,

When we try to rename  table or index name in Oracle, we use a simple command as following;

alter table [prev_table_name] rename to [last_table_name]

If we put into schema names to this command, we can deal with ORA-14047 error. This error raise when we put schema name in front of the last_table_name.

alter table hr.[prev_table_name] rename to hr.[last_table_name] >>> RAISES ORA-14047 ERROR
alter table hr.[prev_table_name] rename to [last_table_name] >> CORRECT ONE

 

It is same with Index renaming.

 

How to remove spaces in a string in Shell March 8, 2011

Filed under: Shell — Akdora @ 9:45 am
Tags: , , ,

I experienced that when you connect to Oracle database from shell and get some data from the table, if the length of the column value is more than 80 letters. Shell puts space in every 80th letter automaticly. I do not know why, but it is really interesting. I counted the number 80 for my environment. It may differ in different systems.

Anyway, I need to remove that interesting spaces. So here is a script to do this.

RETVAL=`echo $RETVAL | sed 's/ //g'`

We use the SED command. Its use like ‘s/[seach_letter]/[replacement]/g’. In my example [seach_letter] is ” ” space and [replacement] is nothing. For example; If we want to replace ”  ” (space) characters with “_” (underscore) character. Here is how we do this:


RETVAL=`echo $RETVAL | sed 's/ /_/g'`

I wrote this quick entry, because if you do not remember how to do something like this and want to google it. It is not easy to find sometimes 🙂